bhylu.com

Advertisements

JS Switch

Switch compares one expression against several case values. Break prevents execution from continuing into the next case.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const day = "Saturday";
switch (day) {
  case "Saturday":
    console.log("Repair club");
    break;
  default:
    console.log("No session");
}

What happens

The matching case prints Repair club.