JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
"switch ... case" Statements
This section provides a quick description of the 'switch ... case' statement.
"switch case" statements are alternative ways of executing statements selectively based on certain conditions. A "switch case" statement has the following generic syntax format:
switch (test_expression) { case expected_value_1: statement_11; statement_12; ... [break;] case expected_value_2: statement_21; statement_22; ... [break;] ... ... default: statement_x1; statement_x2; ... [break;] }
where "test_expression" is used to generate a test value that will be tested against with expected values specified in "case" clauses. The execution of a "switch case" statement goes like this:
Unlike many other programming languages, JavaScript supports both numeric expression and string expression as the switch test expression.
A tutorial example will be given in the next section showing examples of "switch ... case" statements.
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Conditional "if" Statement Examples
"switch ... case" Statement Example
"while" Loop Statement Example
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications