what is the use of a switch statement js code example
Example 1: 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);
Example 2: how to use switch case in javascript
switch (expression) {
case value1:
[break;]
case value2:
[break;]
...
case valueN:
[break;]
[default:
[break;]]
}