Switch Statement in JavaScript
The switch statement is used to perform different action based on multiple cases. How does switch statement work?- Firstly, evaluate the expression once.
- Value of expression will be compared with each case.
- If there would be a match, the associated block of code will execute.
Syntax switch (expression) { case x: // case x code block (statement x) break; case y: // case y code block (statement y) break; default: // execute default code block (statement default) }