Javascript passes objects by reference. This makes perfect sense. But once you start manipulating those objects, everything acts in a way that seem unintuitive. Let me offer
Objects in Javascript can exist by themselves without needing a name. For example:
{}
is a new instance of a dictionary object.
a = {};
creates a new dictionary object and makes a
refer to it. Now
b = a;
makes b
refer to the same underlying object. You can then make a
point somewhere else:
a = "hi";
and b
still points to the same dictionary object it did before. The behaviour of b
is unrelated to how you change what a
points to.