Created
January 17, 2017 01:57
-
-
Save JasonCust/af4b36a87b94678dff3824b65bb21e50 to your computer and use it in GitHub Desktop.
ES2015 Destructuring Assignment Example -- Basic function argument 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) | |
function foo(one, two) { | |
one = one || 1; | |
console.log({one, two}); | |
} | |
*/ | |
function foo(one = 1, two) { | |
console.log({one, two}); | |
} | |
foo(); // { one: 1, two: undefined } | |
foo('FOO'); // { one: 'FOO', two: undefined } | |
foo(undefined, 'BAR'); // { one: 1, two: 'BAR' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment