suppose i have this
var x={}; //x is an address in the memory where object is stored
var z=x; //z=x after execution is equal to z={} right?
now z has nothing to do with x or not related to x after execution so when,
x={name:"Maizere"};
z!=x //true
but, when
x.name="maizere";
alert(z.name)//maizere why?
we are not setting the value of z but x and z relation to x shouldn’t exit anymore
actual code:
x={};
y=x;
x.name="maizere";
alert(y.name)//maizere
I really have no knowledge of how this is working .Can anyone explain this in detail please?
Your initial assumption is wrong;
zis a pointer to the same object asx.When you do
x = { name: "Maizere" };you’re assigning a new object tox.zis still pointing to the original object.In the latter example you’re not creating a new object but changing the original object’s property.
A further example of where the confusion might stem from: the bracket syntax creates a new object instead of modifying the original.