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"
1var myvalue='val1';//or other values; val2 val3 valx
2switch(myvalue) {
3 case 'val1':
4 console.log('var myvalue is '+ myvalue);
5 //other code ...
6 break;
7 case 'val2':
8 console.log('var myvalue is '+ myvalue);
9 //other code ...
10 break;
11 default:
12 // when all the other values not covered with cases above
13 // other code ...
14}
1var price = (function(color) {
2 switch(color) {
3 case 'red':
4 return 10;
5 case 'blue':
6 return 20;
7 default:
8 return 30;
9 }
10})('blue');
11
12console.log(price); // Will print 20
13
1switch(condition){
2 case 'value1' :
3 //code
4 [break;]
5 case 'value2' :
6 //code
7 [break;]
8 .......
9 default :
10 //code
11 [break;]
12}