JS Coding Questions Logo
JS Coding Questions
#222💼 Interview💻 Code

What is the purpose of switch-case

Advertisement

728x90

The switch case statement in JavaScript is used for decision making purposes. In a few cases, using the switch case statement is going to be more convenient than if-else statements. The syntax would be as below,

javascript
1switch (expression)
2  {
3  case value1:
4  statement1;
5  break;
6  case value2:
7  statement2;
8  break;
9  .
10  .
11  case valueN:
12  statementN;
13  break;
14  default:
15  statementDefault;
16  }

The above multi-way branch statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 52

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
222of476