Enables the execution of one or more statements when a specified expression's value matches a label.
switch (expression) {
case label :
statementlist
case label :
statementlist
...
default :
statementlist
}
Use the default clause to provide a statement to be executed if none of the label values matches expression. It can appear anywhere within the switch code block.
Zero or more label blocks may be specified. If no label matches the value of expression, and a default case is not supplied, no statements are executed.
Execution flows through a switch statement as follows:
The following example tests an object for its type.
function MyObject() {
...}
switch (object.constructor){
case Date:
...
case Number:
...
case String:
...
case MyObject:
...
default:
...
}