If I declare two variables to be equal to each other and then I edit one of them, will both variables still be equal? For example, if I do this:
let arr1 = [2, 3, 4, 5];
let arr2 = arr1;
var c = arr1.pop()
console.log(arr1); // prints [ 2, 3, 4 ]
console.log(arr2); // prints [ 2, 3, 4 ]
Both variables are still equal even though I have not stated arr2 = arr1
after the pop function.
However, if I redeclare the array:
let arr3 = [2, 3, 4, 5];
let arr4 = arr3;
arr3 = [1];
console.log(arr3); // prints [ 1 ]
console.log(arr4); // prints [ 2, 3, 4, 5 ]
arr4
maintains its value.
Could someone explain to me why this is so? Thank you!