JavaScript - Switch Case

The switch statement is used to perform different actions based on different conditions.The JavaScript switch statement is used to execute one code from multiple expressions. It is just like else if statement that we have learned in previous page. But it is convenient than if..else..if because it can be used with numbers, characters etc.

Syntax :-

Example :-


Entering switch block

Good job

Exiting switch block

Set the variable to different value and then try...

Common Code Blocks

Sometimes you will want different switch cases to use the same code.

Example :-


Soon it is Weekend