Memory Address

This is one of the most common sources of bugs. Primitives (numbers, strings) are copied by value. **Objects, however, are copied " by reference " **.

let user = { name: "John" };
let admin = user; // Copies the reference, not the object itself

admin.name = "Peter"; // We change it via admin...
alert(user.name); // ...and John's name became "Peter" too!

How to make a real copy?

If you need actual cloning (a new object with the same data):

let clone = Object.assign({}, user);
// Or using the modern spread operator:
let clone2 = { ...user };
Warning

Object.assign and {...} perform a " shallow " copy. If there are other objects nested inside, they will still remain as references.