I found this question in the h5bp/Front-end-Developer-Interview-Questions repository.
One example confused me.
var foo = {n: 1};
var bar = foo;
foo.x = foo = {n: 2};
// foo.x is undefined /* WHY??? */
bar.y = bar; // This works however.
bar.y.y.y;
//> Object {n: 1, x: Object, y: Object}
var xoxo = foo = {n: 2};
//> Object {n: 2}
With bar, I assigned the object literal's x property to the object itself and what appears to be happening now, is that it's referencing itself through x "infinite times".
I expected the same behaviour from the line foo.x = foo = {n: 2};. What happens with foo.x and why? If you explained the steps that will get me to the right answer, I'd appreciate it
Wanted to see if there is a flaw in my right-hand assignment logic, but xoxo seems to be assigned as I expected.