let a = [1, 2, 3]
let b = a
a = [1, 2]
console.log(b)
I expected that the result will be 1, 2 but it is 1, 2, 3
>Solution :
You’ve changed the pointer of the variable a to a new array, but the old array still exists because b is still pointing to it. All you’ve done is reassign the array that the variable a is now pointing to.
This is working as expected. You’ll get the result you were trying to achieve by mutating the array a is pointing to instead of completely reassigning it. Ie
let a = [1, 2, 3]
let b = a
a.pop()
console.log(b)