Previous
If Condition
ABC of JavaScript : A JavaScript Tutorial
Switch Case
Next
For Loop

Switch Case

Syntax:
switch (VARIABLE) {
case CONDITION : STATEMENT
break
case CONDITION : STATEMENT
break
case CONDITION : STATEMENT
break
default : STATEMENT
}

This has a similar function as the If condition - but it is more useful in situations when there is many possible values for the variable. Switch will evaluate one of several statements, depending on the value of a given variable. If no given value matches the variable, the default statement is executed.


Previous
If Condition
Contents Next
For Loop