1switch(expression) {
2 case x:
3 // code block
4 break;
5 case y:
6 // code block
7 break;
8 default:
9 // code block
10}
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"
1let color = "black";
2
3switch(color){
4 case "red":
5 console.log("color is red");
6 break;
7 case "white":
8 console.log("color is white");
9 break;
10 case "black":
11 console.log("color is black");
12 break;
13 default:
14 console.log("unknow color");
15}
1var day = new Date();
2switch(day.getDay())
3 {
4 case 0:
5 console.log("Today is Sunday");
6 break;
7 case 1:
8 console.log("Today is Monday");
9 break;
10
11 case 2:
12 console.log("Today is Tuesday");
13 break;
14
15 case 3:
16 console.log("Today is Wednesday");
17 break;
18
19 case 4:
20 console.log("Today is Thursday");
21 break;
22
23 case 5:
24 console.log("Today is Friday");
25 break;
26
27 case 6:
28 console.log("Today is Saturday");
29 break;
30
31 default:
32 console.log("No Information Found");
33 break;
34 }
35
36// Output : Today is Monday
37
1var a=3;
2switch(a)
3{
4 case 1:
5 console.log("Value of a is 1");
6 break;
7
8 case 2: // grouped three cases
9 case 3:
10 case 4:
11 console.log("Value of between 2 and 4");
12 break;
13
14 default:
15 console.log("Value of a not matched");
16 break;
17}
18
19// Output: Value of between 2 and 4
20
1switch(x){
2 case value1: // if x === value1
3 ...
4 break;
5 case value2: // if x === value2
6 ...
7 break;
8 default: // if x not match
9 ...
10}
11