Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active March 15, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vielhuber/6ff0cc5b9def7108713d to your computer and use it in GitHub Desktop.
Save vielhuber/6ff0cc5b9def7108713d to your computer and use it in GitHub Desktop.
default parameter values in functions (pre/post es6) #js
// es6
function foo(a,b = 2) {
alert(a+b);
}
// pre es6
function foo(a,b) {
b = b || 2;
alert(a+b);
}
function foo(a,b) {
b = typeof b !== 'undefined' ? b : 2;
alert(a+b);
}
foo(1); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment