JavaScript witch statement

The switch statement is a type of switch used to perform different actions based on different conditions.
In large numbers SWITCH statement can replace performing IF ... ELSE ... and ELSE IF ... tests.
The SWITCH statement contains in itself CASE, BREAK, DEFAULT statements.



Syntax:


switch(expression) {
  case a:
     case //condition 1:
    statement;
    break;
  case b:
     case //condition 2:
    statement;
    break;
      case c:
     case //condition 3:
    statement;
    break;
  default:
    // statement for end
    break;
}  
  



Example Switch Statement



var object = "aeroplan";

switch (object) {
 case "truck":
   document.write("Tom is driver");
   break;
  case "boat":
   document.write("Tom is sailor");
   break;  
  case "aeroplan":
   document.write("Tom is pilot");
   break; 
 default:
    document.write("Tom is nothing");
  break; 
}