Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 22, 2019 14:30
Show Gist options
  • Save NyaGarcia/6783e6686c4e2ae5ea69f4001bdeb363 to your computer and use it in GitHub Desktop.
Save NyaGarcia/6783e6686c4e2ae5ea69f4001bdeb363 to your computer and use it in GitHub Desktop.
Using default values when destructuring
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