Created
September 22, 2019 14:30
-
-
Save NyaGarcia/6783e6686c4e2ae5ea69f4001bdeb363 to your computer and use it in GitHub Desktop.
Using default values when destructuring
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 pokemon = { | |
id: 1, | |
name: 'Squirtle' | |
}; | |
const { type, name } = pokemon; | |
console.log(name); //Result: Squirtle | |
console.log(type); //Result: undefined | |
//Assigning default value to the type variable | |
const { type = 'Water', name } = pokemon; | |
console.log(type); //Result: Water |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment