Conditional Statements - Part 4
Notes:
JavaScript switch case statement:
When there are more than one alternative choices present, we use switch case statement.
Browser executes the case whose label matches the expression given in a switch case parenthesis
syntax:
switch(expression){
case label-1:{
statements;
}
break;
case label-2:{
statements;
}
break;
…
default:{
statements;
}
}
Example Code:
var choice = 1;
switch(choice){
case 1:{
document.write("Ceiling fan is on");
}
break;
case 2: {
document.write("AC is on");
}
break;
case 3:{
document.write("Table fan is on");
}
break;
default:{
document.write("Invalid choice");
}
break;
}
document.write("Outside switch statement");
Interview Questions: