"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:
   case expected_value_2:

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

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

Flow Control Statements

 What Is a Statement?

 Conditional "if" Statements

 Conditional "if" Statement Examples

"switch ... case" Statements

 "switch ... case" Statement Example

 "for" Loop Statements

 "for" Loop Statement Example

 "while" Loop Statements

 "while" Loop Statement Example

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 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


 PDF Printing Version