The switch statement part 3
The break Keyword
When JavaScript code reaches a break keyword, it breaks out of the switch block.
This will stop the execution of more code and case testing inside the block.
Usually, a break should be put in each case statement.
What is the output of this code?
var x = 3;
switch (x) {
case 1:
document.write(x);
break;
case 2:
document.write(x+2);
break;
default:
document.write(x+5);
}
var x = 3;
switch (x) {
case 1:
document.write(x);
break;
case 2:
document.write(x+2);
break;
default:
document.write(x+5);
}
Ans 8
Comments
Post a Comment