In Javascript, why do the push and unshift functions on a list affect other arrays that the array is assigned to?
For example, if I have an array called list1 and another array called list2 and I assign list1 to list2 as shown below and I push a value into list1, why does list2 also change?
var list1 = [1,2,3];
var list2 = list1;
list1.push(4);
alert(list2);
// Alerts [1,2,3,4]
This is different if I assign an array to list1.
var list1 = [1,2,3];
var list2 = list1;
list1 = [1,2,3,4];
alert(list2);
// Alerts [1,2,3]
Can somebody please help? This is confusing and makes no sense at all.