//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
case "yellow":case "pink":case "orange":
darkOrLight = "Light";
break;
case "blue":case "purple":case "brown":
darkOrLight = "Dark";
break;
default:
darkOrLight = "Unknown";
}
//darkOrLight="Light"var myvalue='val1';//or other values; val2 val3 valx
switch(myvalue) {
case 'val1':
console.log('var myvalue is '+ myvalue);
//other code ...
break;
case 'val2':
console.log('var myvalue is '+ myvalue);
//other code ...
break;
default:
// when all the other values not covered with cases above
// other code ...
}switch (expression) {
case value1:
//Statements executed when the
//result of expression matches value1
[break;]
case value2:
//Statements executed when the
//result of expression matches value2
[break;]
...
case valueN:
//Statements executed when the
//result of expression matches valueN
[break;]
[default:
//Statements executed when none of
//the values match the value of the expression
[break;]]
}var price = (function(color) {
switch(color) {
case 'red':
return 10;
case 'blue':
return 20;
default:
return 30;
}
})('blue');
console.log(price); // Will print 20