Hope this question is not asked before. In any case I could not find it. I have noticed this variable behavior that only seems to happen with arrays.
The below is how I normally expect variables to behave.
var k = 10,
m = k;
alert(m); //10
k+=1;
alert(m); //10
And now look how they behave with arrays.
var arr = [],
arr2 = arr;
alert(arr2); // empty
arr.push(1);
alert(arr2); // 1
It seems with arrays variables are just references to the same array, with numbers they represent two different numbers that have the same value.
I am sorry if this is a noob question, but I have just noticed it. Is it like this with all complex types? And I was wondering the reason behind this behavior. What does the language achieve by doing this?