Switch statement Javascript
Switch statement Javascript
In this article we are goanna to see about Switch statement Javascript. which is most important when you are going to start your career in JavaScript. Please read and enjoy this article if you want to give any feedback about your experience, we welcome.
Use the switch statement to select one of many code blocks to be executed.
Syntax:
switch(expression) {
case x:
block of statement 1
break;
case y:
block of statement 2
break;
default:
block of statement default
}
How switch statement works:
The switch expression is evaluated once. The value of the expression is compared with the values of each case. If there is a match, the associated block of code is executed. If there is no match, the default code block is executed.
Example:
switch(num) {
case 1:
document.write(“Right”);
break;
case 2:
document.write(“wrong”);
break;
default:
document.write(“Please try again”);
}
Syntax:
Tags:
JavaScript
0 comments
Please leave your comments...... Thanks