let user = {
name: "John",
age: 30,
sayHi() {
alert( this.name );
}
};
let admin = user;
user = null; // overwrite to make things obvious
admin.sayHi(); // John
Here user variable should be a reference type variable and not primitive. So when we assign user variable to admin varaiable so we are not deeply coping the user variable. Therefore both should point to the same location in the heap memory.
So when we assign user = null. So admin variable should also be equal to null since they both should point to the same location in heap memory.
But still admin object is able to access sayHi() method. Can anyone please explain why?