Switch statement syntax

The switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.

Syntax

switch (expression) {
  case value1:
    //Statements executed when the result of expression matches value1
    [break;]
  case value2:
    //Statements executed when the result of expression matches value2
    [break;]
  ...
  case valueN:
    //Statements executed when the result of expression matches valueN
    [break;]
  default:
    //Statements executed when none of the values match the value of the expression
    [break;]
}
expression

An expression whose result is matched against each case clause.

case valueN

A case clause used to match against expression.


Read more: MDN: Switch

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
сніпети з JavaScript
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести