Skip to content

Instantly share code, notes, and snippets.

@bcherry
Created February 22, 2010 23:28
Show Gist options
  • Save bcherry/311655 to your computer and use it in GitHub Desktop.
Save bcherry/311655 to your computer and use it in GitHub Desktop.
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