1switch(expression) {
2 case x:
3 // code block
4 break;
5 case y:
6 // code block
7 break;
8 default:
9 // code block
10}
1switch (a) {
2 case 1:
3 alert('case 1 executed');
4 break;
5 case 2:
6 alert("case 2 executed");
7 break;
8 case 3:
9 alert("case 3 executed");
10 break;
11 case 4:
12 alert("case 4 executed");
13 break;
14 default:
15 alert("default case executed");
16}
1//javascript multiple case switch statement
2var color = "yellow";
3var darkOrLight="";
4switch(color) {
5 case "yellow":case "pink":case "orange":
6 darkOrLight = "Light";
7 break;
8 case "blue":case "purple":case "brown":
9 darkOrLight = "Dark";
10 break;
11 default:
12 darkOrLight = "Unknown";
13}
14
15//darkOrLight="Light"
1switch(type) {
2 case "SomeString":
3 // Functionality
4 break;
5 case "OtherString":
6 // Functionality
7 break;
8 default:
9 // Functionality
10 break;
11}
1function whatToDrink(time){
2 var drink ;
3 switch (time) {
4 case "morning":
5 drink = "Tea";
6 break;
7 case "evening":
8 drink = "Shake";
9 break;
10 default:
11 drink="Water";
12 }
13 return drink;
14}
15console.log(whatToDrink("morning")) //Tea
16console.log(whatToDrink("evening")) //Shake
17console.log(whatToDrink("night")) //Water
18console.log(whatToDrink("daytime")) //Water
1var coll1="kjc;
2
3switch(coll1)
4{
5 case "kjc":
6 alert("youre special");
7 break;
8 case "horizon":
9 alert("worst behaviour");
10 break;
11 case "cmr" :
12 alert("worst character");
13 break;
14 default:
15 alert("kjc is best");
16 break;
17}