After the js reference type value is assigned, it does not affect the previously assigned

after the reference type is assigned, changing one of them will affect the other, as follows:

var obj1 = { name: "hello" };
var obj2 = obj1;
obj2 = {};
console.log(obj1); // {name: "hello"}
console.log(obj2); // {}
Jun.15,2022
The

variable is re-assigned as a whole, which is equivalent to reopening a piece of memory. The memory pointer has changed. It has nothing to do with the original


, followed by a direct change in the direction of the variable, without manipulating the reference object.

Menu