Created
September 30, 2021 14:44
-
-
Save jmaicaaan/9f4c1ab4f6749132c74928c97ba297e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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