Unsure if this question has been asked previously. Nevertheless, I couldn't find it anywhere. I've observed a peculiar behavior that seems to occur only with arrays.
Here is the typical behavior I anticipate from variables:
var k = 10,
m = k;
alert(m); //10
k+=1;
alert(m); //10
Now, observe how they behave when dealing with arrays.
var arr = [],
arr2 = arr;
alert(arr2); // empty
arr.push(1);
alert(arr2); // 1
It appears that with arrays, variables are merely references to the same array, while with numbers, they signify two distinct numbers that happen to have the same value.
I apologize if this seems like a beginner's question, but I recently made this observation. Does this apply to all complex types? Also, what is the rationale behind this behavior? What purpose does the language serve by implementing it in this manner?