The title

var a ={n:1};
var b = a;
a.x=a={n:2};
console.log(a);
console.log(b);
Copy the code

The answer:

If the equal operator goes from right to left, then a is assigned to the new address and a.x is appended to the new address of A. Fix: instead of appending a.x to a’s new address, a’s new address is assigned to A.x, which is stored at A’s old address because A.x’s. The operator is executed prior to =

{n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1} : {n:1

The. Operator takes precedence over the = operator and is executed first. Operation, that is, put the x attribute in the address of A.

3, the assignment operation, assignment from right to left, one assignment, namely {n:2} to a and A.x, at this time a points to the new address {n:2}, and a.x also points to the new address {n:2}.

4, a.x is appended to the original address A, that is, B, a points to the new address

Draw pictures to help you understand.

Additional:

When the data in the new address A memory is changed, a.x will also change accordingly