Listening to udemy, we find that arrays and objects are references, and assigning an already declared array to a new variable (e.g. arr2) itself copies the pointer of an existing array, not a value.
However, if you reallocate the existing array arr itself declared as let at all, why does arr2 output a value before the reallocation rather than the reallocated arr1 value?
let arr1 = [0, 1, 2, 3];
let arr2 = arr1;
arr1.shift();
console.log(arr2); // [ 1, 2, 3]
arr1[0] = 3;
console.log(arr2); // [ 3, 2, 3]
why [0, 1, 2, 3] print?
let arr = [0, 1, 2, 3]
let arr2 = arr
arr = [3, 2, 1, 0]
console.log(arr2) // [0, 1, 2, 3]
solution
'ar2' refers to the memory address of the array '[0, 1, 2, 3]' that 'ar' refers to.
'ar' simply refers to the memory address of the new array '[3, 2, 1, 0]
If 'ar' points to a new array, 'ar2' still points to the memory address of array '[0, 1, 2, 3]'!
So the value was the same.