JavaScript: Not a reference to a variable!
I was fiddeling with some code and got trapped by the way JavaScript handles references. The following code shows very clearly that JavaScript only creates a reference to the value, not to the variable itself!
>>> var a = [1,2,3]
>>> b = a
[1,2,3]
>>> a = [4,5]
[4,5]
>>> b
[1,2,3]
You can see that in the end b is still the initial array, while a has changed it’s value. As long as we only modify the array in a and not a itself b points to the same array. That proves that “b=a” doesn’t create a reference to a but the value of a (but only for arrays and objects!). I guess that is nothing new for JS experts. I just needed to write it down, it hopefully stays in mind better this way :-).