I'm working with array in JavaScript, and my problem is working with variable reference. I have 2 examples below, and it seems to have the same result but it doesn't.
//Example 1
var arr = [1,2,3];
var refArr = arr;
arr[0] = 1;
arr[1] = 3;
arr[2] = 4;
console.log(arr); //[1,3,4];
console.log(refArr); //[1,3,4]
//Example 2
arr = [1,2,3];
refArr = arr;
arr = [1,3,4];
console.log(arr); //[1,3,4];
console.log(refArr); //[1,2,3]
I don't know what's the difference between 2 examples?