Last active
January 22, 2017 05:26
-
-
Save JasonCust/d4488abad9b5ca2d30bc7ec3a9e8598f to your computer and use it in GitHub Desktop.
ES2015 Destructuring Assignment Example -- Basic array destructuring assignment with default value
This file contains hidden or 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
/* 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