Skip to content
techsnow

Control Flow

Switch

switch compares one value against many cases. It is neater than a long chain of else if.

const day = "sat";

switch (day) {
  case "sat":
  case "sun":
    console.log("Weekend!");
    break;
  case "fri":
    console.log("Almost there");
    break;
  default:
    console.log("Weekday");
}

Output

Weekend!