This is related to Javascript a=b=c statements.
I do understand that
foo = foo.x = {n: b}; // console.log(foo) => {n: b}
but
It equals
let tmp = foo; foo = {n: b}; tmp.x = foo;
You could see, that old foo (stored in z in this example) was modified:
foo
z
> z=foo={}; {} > foo.x = foo = {n: b}; { n: 10 } > foo { n: 10 } > z { x: { n: 10 } }