JavaScript Switch Case

You can use multiple if … else … if statements, as in the previous chapter, to create a multiway branch. However, this is not always the best solution, especially when all the branches depend on the value of one variable. As of JavaScript 1.2, you can use a variable statement to handle this exact situation, it works better than the frequent if … if statement.

Syntax

The purpose of the conversion statement is to provide a word to analyze and a number of different words to accomplish depending on the value of the word. The interpreter checks each case against the word value until a match is found. If nothing matches, the default setting will be used.

A break statement indicates the end of a case. If they are removed, the interpreter will continue to make statements in each of these cases.

We will explain the break statement in the main Loop control.

Destructive advertising plays a major role in revolutionary advertising. Try the following code that uses a switch statement without any break statements.