Skip to content

Instantly share code, notes, and snippets.

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 sarahquigley/848253d38ee638b0e463de04e7a9c22b to your computer and use it in GitHub Desktop.
Save sarahquigley/848253d38ee638b0e463de04e7a9c22b to your computer and use it in GitHub Desktop.
Example of ES6 Array Destructuring Assignment - Defaults
/* ES5 */
var cats = [ 'Maru', 'Colonel Meow' ];
var yayCat = cats[0];
var lolCat = cats[2] === undefined ? 'Grumpy Cat' : cats[2];
/* >= ES6 */
var cats = [ 'Maru', 'Colonel Meow' ];
var [ yayCat, , lolCat = 'GrumpyCat' ] = cats;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment