×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

JavaScript Switch



The switch statement evaluates section, compares its Output with case values, and executes the statement associated with the matching case value.

Simple example of javascript switch statement.

Example 1

<script>

var section='B';

var Output;

switch(section){

case 'A':

Output=" section A";

break;

case 'B':

Output="section B";

break;

case 'C':

Output=" section C";

break;

default:

Output="No section";

}

document.write(Output);

</script>

Example 2

<script>

var section='B';

var Output;

switch(section){

case 'A':

Output+=" A section";

case 'B':

Output+=" B section";

case 'C':

Output+=" C section";

default:

Output+=" No section";

}

document.write(Output);

</script>








JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute