Last active
March 13, 2018 14:31
-
-
Save kochmaxence/ad9280ea25b497b70a7c14da5589cc89 to your computer and use it in GitHub Desktop.
Default parameter is used ONLY when it's `undefined`. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters
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
function test( | |
a = '_a default_\n', | |
b = '_b default_\n', | |
c = '_c default_\n', | |
d = '_d default_\n', | |
e = '_e default_\n', | |
f = '_f default_\n' | |
) { | |
console.log(a, b, c, d, e, f); | |
} | |
test( | |
undefined, // a | |
null, // b | |
false, // c | |
[], // d | |
{}, // e | |
'' // f | |
); | |
/* | |
output: | |
» node test6.js | |
_a default_ | |
null false [] {} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment