Skip to content

Instantly share code, notes, and snippets.

@alordiel
Last active May 24, 2017 07:11
Show Gist options
  • Save alordiel/7401d1626e394bbeb0a767e1d4f8ed25 to your computer and use it in GitHub Desktop.
Save alordiel/7401d1626e394bbeb0a767e1d4f8ed25 to your computer and use it in GitHub Desktop.
Passing default values to JS function
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