Created
August 20, 2015 13:04
-
-
Save NoMan2000/5e87d6a3a182cc44f0d5 to your computer and use it in GitHub Desktop.
Testing for optional arguments.
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 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