Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 24, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/2379e0c953203bf8f2a734bcd7959579 to your computer and use it in GitHub Desktop.
Save NyaGarcia/2379e0c953203bf8f2a734bcd7959579 to your computer and use it in GitHub Desktop.
Assigning default values to destructured variables
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