Languages
[Edit]
EN

JavaScript - switch statement with example

4 points
Created by:
Maison-Humphries
791

The switch statement is used to select and execute some code blocks from defined cases using expression.

1. switch syntax

Edit

Where:

  • expression returns a value that will be compared with cases,
  • x, y and z are values that are associated with code blocks,
  • if expression maches some case value (x, y or z) than related code block is executed,
  • if break instruction is placed after a code block, the next code block is not executed,
  • if expression is not matched to any case value default code block is executed.

2. switch statement example

Edit

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join