Last active
May 24, 2017 07:11
-
-
Save alordiel/7401d1626e394bbeb0a767e1d4f8ed25 to your computer and use it in GitHub Desktop.
Passing default values to JS function
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 x(a,b){ | |
a = a || 10; | |
b = b || 12; | |
console.log(a); | |
console.log(b); | |
} | |
x(); | |
// 10 | |
// 12 | |
x(1,2); | |
// 1 | |
// 2 | |
x(null,3); | |
// 10 | |
// 3 | |
x(4,null) | |
// 4 | |
// 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment