I would like to understand why situation 1 and situation 2 do not return the same results.
Situation 1:
var array1 = ["1", "2", "3"];
var array2 = array1.reverse();
console.log(array1); // ["3", "2", "1"]
console.log(array2); // ["3", "2", "1"] Why this doesn't work ?
Situation 2:
var array1 = ["1", "2", "3"];
var array2 = array1;
console.log(array1); // ["1", "2", "3"]
console.log(array2.reverse()); // ["3", "2", "1"] Why this works ?
source
share