If you have an object in javascript and it references another object and then 2nd object changes, you can expect to see the change in the referenced object. However, if the 2nd object is initially undefined, the first object will never reflect new changes. Can anyone potentially explain what is happening under the hood in this code?
//Here we see the reference updated
var myobj = {};
var pointer = myobj;
myobj.value = 1;
console.log(pointer.value);
//Here if we start as undefined, create a reference and then allocate a new object - not so much
var myobj = undefined;
var pointer = myobj;
myobj = {}
myobj.value = 1;
console.log(pointer.value);
This is observed under
$ node --version
v0.8.22
valueproperty), assigned it topointer, and then created the second object withvalue-pointer.valueis undefined