As I understand, object references x
in x = { greet: hi }
stores a reference to object { greet:
hi}
unlike primitive types that hold actual values ( y=10
)
In the following code, console.log(y)
outputs {greet: "hi"}
.
Why does y
object reference is not updated to point to {greet: 'hello'}
when x
obj ref is updated to point to x = {greet: 'hello'}
var x = {greet: 'hi'};
var y = x;
x = {greet: 'hello'};
console.log(y);
console.log(x)