Skip to content

JavaScript switch multiple cases | Example code

  • by

Use the fall-through feature of the JavaScript switch statement to apply multiple cases. A matched case will run until a break (or the end of the switch statement) is found.

JavaScript switch with multiple cases

A simple example code makes multiple case labels.

<!DOCTYPE html>

      var varName = "larry"

      switch (varName)
       case "afshin":
       case "saeed":
       case "larry": 
       alert('Hello' + " " + varName);


       alert('Default case');




JavaScript switch multiple cases

More example

function theTest(val) {
  var answer = "";
  switch( val ) {
    case 1: case 2: case 3:
      answer = "Low";
    case 4: case 5: case 6:
      answer = "Mid";
    case 7: case 8: case 9:
      answer = "High";
      answer = "Massive or Tiny?";
  return answer;


Do comment if you have any doubts or suggestions on this JS switch case topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.