Skip to content

Instantly share code, notes, and snippets.

@JasonCust
Last active January 22, 2017 05:26
Show Gist options
  • Save JasonCust/d4488abad9b5ca2d30bc7ec3a9e8598f to your computer and use it in GitHub Desktop.
Save JasonCust/d4488abad9b5ca2d30bc7ec3a9e8598f to your computer and use it in GitHub Desktop.
ES2015 Destructuring Assignment Example -- Basic array destructuring assignment with default value
/* ES5 equivalent (ignoring assignment of intended falsy values)
var arr = [];
var one = arr[0] || 1;
var two = arr[1];
*/
let arr = [];
let [one = 1, two] = arr;
console.log({one, two}); // output: { one: 1, two: undefined }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment