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
} |
Arguments
-
expression
-
The expression to be evaluated.
-
label
-
An identifier to be matched against expression. If label === expression, execution starts with the statementlist immediately after the colon, and continues until it encounters either a break statement, which is optional, or the end of the switch statement.
-
statementlist
-
One or more statements to be executed.
Remarks
Example
The following example tests an object for its type.
  | Copy Code |
---|
function MyObject() {
...}
switch (object.constructor){
case Date:
...
case Number:
...
case String:
...
case MyObject:
...
default:
...
} |
Requirements
See Also