Skip to content

Instantly share code, notes, and snippets.

@JasonCust
Created January 17, 2017 01:57
Show Gist options
  • Save JasonCust/af4b36a87b94678dff3824b65bb21e50 to your computer and use it in GitHub Desktop.
Save JasonCust/af4b36a87b94678dff3824b65bb21e50 to your computer and use it in GitHub Desktop.
ES2015 Destructuring Assignment Example -- Basic function argument destructuring assignment with default value
/* 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