Use Case label in switch statement - Javascript Statement

Javascript examples for Statement:switch

Description

Use Case label in switch statement

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w w  w  .j  ava  2 s.c o  m
var a = 1;
switch (a) {
  case 0:
      // do stuff
      break;
  case 1:
  case 2:
      console.log(a); // alerts "1"
      break;
  default:
      // do default stuff
      break;
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials