Let's say we start with this:
var foo = {n:1};
var bar = foo;
In JavaScript, what is the order in which the following assignments are carried out:
foo.x = foo = {n:2};
When I looked up answers to this I found several that seemed to suggest that assignments happen from RIGHT TO LEFT, eg:
foo = {n:2};
foo.x = foo;
In which case we would expect:
console.log(foo) //{n:2, x:Object} - (a circular reference back to foo)
However what I see in the console when I actually do this suggests that assignments actually happen from LEFT TO RIGHT:
console.log(foo) //{n:2}
console.log(bar) //{n:1, x:Object}
--> The {n:1} obj gets an 'x' property, and foo gets reassigned to a new object {n:2}
Can someone clarify for me the order of operations when there are multiple assignments in one line?
Also, what is the underlying rule that distinguishes the above scenario from a situation like the following: Multiple variable assignments in one row
Some of the answers in the above question claim that assignments of primitives are carried out RIGHT TO LEFT...