In assignments, strange things happen here:
foo.c = (foo = {})
The reference to foo.c first resolved and points to the old foo object before the internal expression is evaluated, where foo will be re-assigned with the literal {} emtpy object. So your code is equivalent
var foo1 = {}; var foo2 = {}; foo1.c = foo2; console.log(foo2.c)
You can also try
var foo = {}, old = foo; foo.c = foo = {}; console.log(old, foo, old.c===foo);
source share