javascript,switch,Syntax for switch,Javascript example for switch case

In javascript switch case is usually used for eliminating multiple if, else if and else statements.

Syntax for switch:

switch(variable)
{
caseany-constant-value:
//group of javascript statements;
break or continue or return statement;
case any-constant-value:
//group of javascript statements;
break or continue or return statement;
default:
//group of javascript statements;
break or continue or return statement;
}
Note: a constant value can be any of the following types. a. Number ( can be a number with or without decimal values ) b. String c. Boolean Note: break keyword is optional however, it is usually needed, since otherwise code execution will continue to the body of the next case block.

Javascript example for switch case:

     <html>
     <head>
     <title>Javascript switch case example</title>
     <script language="javascript" type="text/javascript">
      functionDisplayDayName(dayno) {
        switch (dayno) {
        case1:
        alert('monday'); 
        break;
        case2:
        alert('tuesday');
        break;
        case3:
        alert('wednesday');
        break;
        case4:
        alert('thursday');
        break;
        default:
        alert('sunday');
        break;
            }
        }
         </script>
         </head>
        <bodyonload="DisplayDayName(2)">

       </body>
       </html>