switch statmenet javscript code example
Example 1: 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 2: switch statement javascript
function caseInSwitch(val) {
var answer = "";
switch(val) {
case 1:
answer = "alpha";
console.log(answer);
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}
return answer;
}
caseInSwitch(1);