Switch on string value - Javascript Statement

Javascript examples for Statement:switch

Description

Switch on string value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript">
var color;
color = "red";
switch (color){
    case"red"://from  w  ww .ja v a 2 s  . co m
    console.log("RED");
    break;
    case "white":
    console.log("WHITE");
    break;
    case "blue":
    console.log("BLUE");
    break;
    default:
    console.log("default");
}

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

Related Tutorials