How to use switch case in javascript?

The switch statement is used to perform different actions based on different conditions.

Example:


  let fruit = "banana";
  switch(fruit) {
      case "apple":
          console.log("This is an apple");
          break;
      case "banana":
          console.log("This is a banana");
          break;
      default:
          console.log("Unknown fruit");
  }
  // Outputs: This is a banana
  

Beginner's Guide to JavaScript