FrontendDeveloper.in

JavaScript question detail

What is the purpose of switch-case

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,

switch (expression)
{
case value1:
statement1;
break;
case value2:
statement2;
break;
.
.
case valueN:
statementN;
break;
default:
statementDefault;
}

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.

Back to all JavaScript questions
Get LinkedIn Premium at Rs 399