Why a referenced object is not set to null when parent object is set to null in JavaScript?
var objA = { 1 : "hello" };
var objB = objA;
objA = null;
console.log(objB); // { 1 : "hello" }
Why objB is not set to null? How object referencing works here?
Variables never “contain” objects, they simply contain a reference to an object.
var objB = objA;simply copies the reference stored inobjA, making them point to the same object. WhenobjAis set tonull, it means that it no longer points to anything. However,objBstill contains a reference to the object.