Last active
March 15, 2018 17:13
-
-
Save vielhuber/6ff0cc5b9def7108713d to your computer and use it in GitHub Desktop.
default parameter values in functions (pre/post es6) #js
This file contains 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
// 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