i

JavaScript

switch statement

In order to perform different actions based on the different actions specified, the switch statement can be used.

Syntax:

switch (expression) {

case a:

// code block

break;

case b:

// code block

break;

default:

// code block

}

break statement:

break is used to break out of the switch case. If the break statement is not given, then the next case will be executed even if it does not match. The last case need not have a break statement because there is no case after it.