Statements and declarations

switch statement

Try the free JavaScript compiler

Evaluates a discriminant and searches for a case using strict equality. Execution begins at the matching body or default, if present, and continues until completion or abrupt control transfer.

Formal Syntax & Structure

javascript syntaxjavascript
switch (value) { case label: statements; break; default: statements; }

Working Example

Example Snippetjavascript
switch (2) { case 1: console.log("one"); break; case 2: console.log("two"); break; }
JavaScript Reference