In this example, I have shared switch statement multiple cases in JavaScript. Use the fall-through feature of the switch statement. A matched case will run until a break (or the end of the switch statement) is found, so you could write it like:
1 2 3 4 5 6 7 8 9 10 11 12 | //Switch statement multiple cases in JavaScript. switch (varName) { case "afshin": case "saeed": case "larry": alert('Hey'); break; default: alert('Default case'); } |
Multiple Criteria in a Single Case inside a Switch Statement
There is one hacky switch style that allows you to specify ranges:
1 2 3 4 5 6 7 | switch (true) { case blah >= 0 && blah <= 3: //do this break default: //do that } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.