I have a simple question
let obj1 = {};
obj2= obj1;`
Here obj1 and obj2 are referencing the same object in the memory i.e. obj1===obj2 --> true
. So by this logic any operation on obj2 will affect obj1.
Now if I assign a property to obj2
let obj1 = {};
obj2 = obj1;
obj2['a'] = {};
obj2 = obj2['a']; // why this operation didn't change obj1, if they are referencing the same object ?
console.log(obj1); // -- > { a: {} };
console.log(obj2); // -- > {};
now obj1===obj2 --> false
why is this ?
Also How come obj2 = {} is different then obj2 = obj2['a']
?
A screenshot for clarifying myself
Thanks for your help in advance.