This is my example code:
var foo = {a : 1};
var bar = foo;
console.log(bar.a);//1, as expected
foo.a = 2;
console.log(bar.a);//2, as expected, as objects are passed by reference
foo = {a : 10};
console.log(bar.a);//2, not expected, I expected 10
The last log doesn't give the expected result.
Thinking that foo = {a : value}
is the same as foo.a = value
I expected that last result was 10.
What's wrong with my expectation? I think I am missing a big lesson here.