JS Tutorial



JS SWITCH STATEMENT


JavaScript switch Statement

The switch statement is used to perform different actions based on different conditions โ€” like a clean alternative to multiple if-else statements.

๐Ÿ”น Use Case: Handling menu options, days, grades, status, etc.

๐Ÿ“Œ Syntax

switch(expression) {
  case value1:
    // code block
    break;
  case value2:
    // code block
    break;
  default:
    // default code block
}

๐Ÿ” Example: Detecting the Day

let day = "Wednesday";
switch(day) {
  case "Monday":
    console.log("Start of the week");
    break;
  case "Wednesday":
    console.log("Mid-week check-in");
    break;
  case "Friday":
    console.log("Almost weekend!");
    break;
  default:
    console.log("It's just a regular day");
}

๐Ÿงช Try It Yourself


Message will appear here
๐Ÿ“˜ Summary:
The switch statement simplifies complex conditional logic and is best used when checking a single value against multiple possibilities.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review