Skip to main content
D
JavaScript
JavaScript Switch

JavaScript Switch

JavaScript switch statements check a value against many cases.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript uses the switch statement as a cleaner alternative to writing many `if...else` statements. Developers pass a single value into the switch, and the computer jumps directly to the matching case.

Example

Example
1/* this uses a switch */
2switch(day) {
3  case 1:
4    text = "Monday";
5    break;
6  case 2:
7    text = "Tuesday";
8    break;
9}

Key Points

  • The `switch` statement evaluates one expression.
  • The `case` keyword defines a possible match.
  • The `break` keyword stops the switch from running further.
  • The `default` keyword runs if no cases match.

Up Next

Continue your journey with the next topic.

Go to JS For Loop