Switch Statement in JavaScript

Level 295 keystrokes

A switch statement evaluates an expression and executes the matching case block.

JavaScript code

// Declare a variable with value 1
1let day = 1;
// switch evaluates the value of day
2switch (day) {
// day is 1: print "Mon", then break exits the switch
3 case 1: console.log("Mon"); break;
// default runs if no case matches
4 default: console.log("Other");
5}

Output

Mon
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ;× 4
  • "× 4
  • (× 3
  • )× 3
  • :× 2
  • .× 2
  • {× 1
  • }× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice