I’m not sure what you are suggesting… that using the spread operator will mirror the array being copied so that the copy stays in sync when the original array is changed?
By itself would error out but as seen as shown in the following I can see its the other way round from what I described. Using the spread operator copies it once but using the equal operator mirrors it.
let thisArray = [true, true, undefined, false, null];
let thatArray = [...thisArray];
// let thatArray = thisArray;
// console.log(thisArray);
// console.log(thatArray);
thisArray[0] = 42;
console.log(thisArray);
console.log(thatArray);
If you want to actually copy, then you need to use the spread.
Variables in Javascript can only hold one value. For more complex data, like objects and arrays, the variable stores the location of the object or array in memory. So the code in the first post creates a new variable that points to the same place in memory. The spread operator makes a new array in another place in memory.
What you are doing here is not copying the array, rather you are creating a reference to the original array.
Now if you do thatArray[0] = false; and try logging console.log(thisArray) you will see that the value of thisArray (which is the main array) has changed. In other words, you havent copied the array, rather you accessed it with a different variable.
Now lets see what happens when you use the spread operator with an example →
As you can see the origial array hasnt changed rather, you could modify the array you wanted to change(the copied array) without modifying the original one.
Arrays are mutable and in some cases in real life situations, you dont want that so you might need to occassionally use the spread operator to copy the array rather than accessing it.