The switch and with Statements

In this lesson, you will have an overview of all flow-control statements provided by the JavaScript language.

The switch statement

As an alternative to compound if statements, JavaScript defines the switch statement.

Illustration

Here is the concept explained in the form of an illustration:

Syntax #

The switch statement has the following syntax:

Press + to interact
switch (expression) {
case value1:
statement
break;
case value2:
statement
break;
// "case" can be repeated
case valueN:
statement
break;
default:
statement
}

The expression is evaluated, and its value is checked against values in ...

Access this course and 1400+ top-rated courses and projects.