Switch / Case
Switch Syntax
switch(expression) {
case value :
// Code to run
break; // optional to break out of the switch block
case value :
// Code to run
break; // optional to break out of the switch block
/** You can have any number of case statements. **/
default : // Optional case to catch any other possibilities
// Code to run
}Example 1 - Switch on Number
Example 2 - On Text
Final Thoughts
Last updated