0 votes
in JavaScript by
What is the purpose of switch-case?

1 Answer

0 votes
by

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.

...