Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Created September 30, 2021 14:44
Show Gist options
  • Save jmaicaaan/9f4c1ab4f6749132c74928c97ba297e7 to your computer and use it in GitHub Desktop.
Save jmaicaaan/9f4c1ab4f6749132c74928c97ba297e7 to your computer and use it in GitHub Desktop.
const person01 = {
name: 'JM'
};
/**
* Clone/copy all the values in `person01`
*/
const person02 = { ...person01 };
/**
* Mutating `person02` will *not* cause effect also on `person01` because
* `person01` was not assigned/passed by the same reference of `person01`
* Since we copy `person01` it creates a new reference that only `person02` has
*/
person02.name = 'JM Santos';
console.log('person01', person01); // JM
console.log('person02', person02); // JM Santos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment