I have read that a variable is stored as a memory reference in js.
So for var a = 5, the memory location with value 5 is assigned to a.
I tried running this on node.js:
var a = 5;
var b = {
val: a
};
a = 6;
I expect b.val to be 6 but is 5,
If I run:
var a = 5;
var b = {
val: a
};
var c = {
value: b
}
b.val = 6;
Than c.value.val is 6.
If they are all memory objects, why is there a difference in outputs?