Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Created August 20, 2015 13:04
Show Gist options
  • Save NoMan2000/5e87d6a3a182cc44f0d5 to your computer and use it in GitHub Desktop.
Save NoMan2000/5e87d6a3a182cc44f0d5 to your computer and use it in GitHub Desktop.
Testing for optional arguments.
function sum(a, b, c, d) {
// Note: no `break` needed
switch (arguments.length) {
case 0: a = 1;
case 1: b = 2;
case 2: c = 3;
case 3: d = 4;
}
return a + b + c + d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment