It seems that your question consists of two sub questions:
- why "var prevUsers = users;" doesn't work
- what is the difference between "var prevUsers = users;" and "var prevUsers = [...users];"
I would need a little more detail (e.g., full code) to answer the first, but I can provide one for the second.
See the code below:
// creating array users
let users = [1, 2, 3, 4, 5];
// assigning users to prevUsers
var prevUsers = users;
console.log(prevUsers);
// modifying (deleting first element of) users
users.splice(0, 1);
console.log(prevUsers);
console.log(users);
You can see that assigning users to prevUsers is actually not a good practice because it is assigning the reference to the location of the users array, not creating a new array with identical content. Here's where the spread operator (...) comes in to play:
// creating array users
let users = [1, 2, 3, 4, 5];
// creates new array with the content from users and assigns to prevUsers
var prevUsers = [...users];
// modifying (deleting first element) users
users.splice(0, 1);
console.log(prevUsers);
console.log(users);
Using the spread operator, you can create a new array, place the elements of users inside it, and then assign the new array to prevUsers. Since the two arrays are different arrays, "users.splice(0, 1);" will not affect elements inside prevUsers.