Created
September 21, 2019 14:43
-
-
Save NyaGarcia/456eafcc61027ce48ac9d460b673acad to your computer and use it in GitHub Desktop.
Renaming object properties while destructuring them
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 squirtle = { type: 'Water', ability: 'Torrent' }; | |
//Normal property destructuring: | |
const { type, ability } = squirtle; | |
console.log({ type }, { ability }); //Result: { type: 'water' } { ability: 'torrent' } | |
//Renaming properties | |
const { type: squirtleType, ability: superAwesomeAbility } = squirtle; | |
console.log({ squirtleType }, { superAwesomeAbility }); //Result: { squirtleType: 'Water' } { superAwesomeAbility : 'Torrent' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment