Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

case — a clause in a switch statement

The case keyword marks an execution entry point within a switch statement. Matching uses strict equality, and without break or another interruption, execution continues into subsequent clauses.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

switch (value) {
  case expression:
    statements;
    break;
  default:
    fallbackStatements;
}

case expression: introduces a clause inside switch; it is not a standalone statement. case is a reserved word, so it cannot be a variable name.

The switch expression is evaluated once. The case expressions are checked in source order until the first match under the rules of ===, without type conversion: 2 and "2" do not match. A selector can be an expression, not just a literal. The optional default clause supplies the entry point when no case matches.

Once execution starts, subsequent clauses are not tested again: execution continues through them until interrupted or until switch ends. break exits switch, while return exits the function. Multiple empty case clauses can share code. Clauses do not create separate scopes for let and const; use {} blocks to isolate declarations.

Examples

function classify(value) {
  switch (value) {
    case "2":
      return "string";
    case 1:
    case 2:
      return "small number";
    default:
      return "other";
  }
}

console.log(classify("2"));
console.log(classify(2));
console.log(classify(3));

Result

string
small number
other

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources