TypeScript Switch Case Statement

This acts like a multiple if / else if / else chain. Checks an value against a list of cases, and executes the first case that is true. If no matching case found, it executes the default case. The break(optional) statements with case indicate to the interpreter to end the particular case.

Syntax

TypeScript Switch Case Example 1

Try it Yourself

If you forget a break statement, which is optional than script will run from the case where condition is met, and will run the case after that regardless if condition was met.

TypeScript Switch Case Example 2

Try it Yourself