switch example in javascript
Example 1: js switch case
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 2: 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 3: Javascript switch case code format
switch(type) {
case "SomeString":
break;
case "OtherString":
break;
default:
break;
}
Example 4: js switch
var myvalue='val1';
switch(myvalue) {
case 'val1':
console.log('var myvalue is '+ myvalue);
break;
case 'val2':
console.log('var myvalue is '+ myvalue);
break;
default:
}
Example 5: switch case in js
var coll1="kjc;
switch(coll1)
{
case "kjc":
alert("youre special");
break;
case "horizon":
alert("worst behaviour");
break;
case "cmr" :
alert("worst character");
break;
default:
alert("kjc is best");
break;
}