It is right associative. It's simply that the identifier a
is bound to a reference before the statement executes.
We can witness this with the following:
var a, b;
a = b = { n: 1 };
a.x = a = {n: 2}; // a.x refers to the x property of the value a references
// before this statement executes
console.log(a); // {n: 2}
console.log(b); // {n: 1, x: {n: 2}}
If =
were left associative, b.x
would be a circular reference back to b
after the third line executes, but it isn't.
Can anyone explain why a.x is undefined?
Yes, this is what happens when the line a.x = a = {n: 2}
executes:
- The value
{n: 2}
is assigned to the variable a
- The value
{n: 2}
is assigned to the x
property of the object that a
referred to before the statement started executing.
Nothing is assigned to the x
property of a
's new value. That's why a.x
is undefined
.