Created
September 24, 2019 16:00
-
-
Save NyaGarcia/2379e0c953203bf8f2a734bcd7959579 to your computer and use it in GitHub Desktop.
Assigning default values to destructured variables
This file contains 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