Last active
January 22, 2017 05:26
-
-
Save JasonCust/4186d01d02b37463f25c11b8ddf295c2 to your computer and use it in GitHub Desktop.
ES2015 Destructuring Assignment Example -- Basic object 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 obj = {}; | |
var one = obj.one; | |
var two = obj.two || 2; | |
*/ | |
let obj = {}; | |
let {one, two = 2} = obj; | |
console.log({one, two}); // output: { one: undefined, two: 2 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment