When assigning arr2 = arr, then arr2isarr. Any changes made to arr will also change arr2. In other words, it’s just giving arr another name.
On the other hand, arr2 = [...arr] will make arr2 a copy of arr. As a copy, this makes them distinct, so changes to one won’t show up in the other (it’s a shallow copy though, but we don’t need to care about that just yet).
I always say that I have an advantage in that I learned the C language first because things like this make perfect sense there.
num1 = num2;
… works exactly as you would expect - it copies the value of num2 into the memory slot of num1 and now you have two copies of the variable.
arr1 = arr2;
… you aren’t copying the array, but are copying the address of the array. So, you still have only one copy of the array, but two addresses that point to the same array. This is also why when you pass an array (or any object) into a function and make changes inside the function to that “copy” of the array, the original is changed. This is because you are not sending the array itself but the address of it, also called “by reference”.
So, if you truly want two copies of an array, you have to make a completely new array and assign that to the new variable.
The pre-ES6 way to do this was:
arr1 = arr2.slice();
… but now we have:
arr1 = [...arr2];