JavaScript Switch Case

from JavaScript 1.2 onwards, we can use a switch statement which provide alternative to if statements, and it does better than repeated if…else if statements.

Syntax:

The expression is evaluated and compared to each case label. If a match is found, the corresponding statement is executed. If no match is found, the defaultStatement (if provided) is executed. The break statement exits the switch statement.

example code:

Output:  Today is Monday

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top