Created
September 14, 2019 15:18
-
-
Save NyaGarcia/66d49dc57cfcc7f095df0a15e28388ad to your computer and use it in GitHub Desktop.
Copying an object immutably with the spread operator
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 mySquirtle = { | |
name: 'Squirtle', | |
type: 'Water', | |
hp: 100 | |
}; | |
const anotherSquirtle = { ...mySquirtle }; | |
anotherSquirtle.hp = 0; | |
console.log(anotherSquirtle); //Result: { name: 'Squirtle', type: 'Water', hp: 0 } | |
console.log(mySquirtle); //Result: { name: 'Squirtle', type: 'Water', hp: 100 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment