Because you re-assigned foo to an object with a single property, { n: 2 }
.
In JavaScript, expressions are evaluated from right to left. So when you try to access foo.x
, you are trying to get the value of x
from newly assigned value of foo, { n: 2 }
, which is undefined
.