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.

obj2 = obj2.areassignsobj2so it no longer points toobj1.obj2 = obj2[a]you're reassigning the identifier nameobj2to a completely new value, instead of just adding a property.obj2.a = {}; obj2 = obj2.a;,obj1points to the same object as it did before.obj2does not; it points to theaproperty of the object pointed to byobj1.obj1 === obj2.a. Then, if you add the propertybtoobj2, you simply nest another property inobj2. Sinceobj1still points to the “root” object, of course it reflects all the changes.