Created
February 22, 2010 23:28
-
-
Save bcherry/311655 to your computer and use it in GitHub Desktop.
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 foo(one, two, three) { | |
one = one || "defaultvalue"; // assigns default value if one is falsy (null, undefined, 0, "0", false, etc.) | |
two = two == null ? "defaultvalue" : two; // assigns default value if 'two' is not null or undefined (so you can pass things like 0 or false) | |
three = three === undefined ? "defaultvalue" : three; // assigns default value if three is not undefined (so you can pass null) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment