? clause javascript code example
Example 1: javascript switch statement multiple cases
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";
}
Example 2: javascript switch assignment
var price = (function(color) {
switch(color) {
case 'red':
return 10;
case 'blue':
return 20;
default:
return 30;
}
})('blue');
console.log(price);