Switch Statement

|

The switch statement of JavaScript
The switch statement is basically an enhanced version of the "if-else" statement that is more convenient to use when you have code that needs to choose a path from many to follow. Let's have a look at this statement's general syntax:

Syntax:
switch (expression){
case value1:
statement;
break;
case value2:
statement;
break;
"
"
default : statement;
}

Example:
switch (favoritemovie){
case "Titanic":
alert("Not a bad choice!")
break;
case "Water World":
alert("No comment")
break;
case "Scream 2":
alert("It has its moments")
break;
default : alert("I\'m sure it was great");
}




 

©2009