switch case operator js code example
Example 1: js switch case
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 2: Javascript switch case code format
switch(type) {
case "SomeString":
break;
case "OtherString":
break;
default:
break;
}
Example 3: javascript switch
let color = "black";
switch(color){
case "red":
console.log("color is red");
break;
case "white":
console.log("color is white");
break;
case "black":
console.log("color is black");
break;
default:
console.log("unknow color");
}
Example 4: switch js
switch (expr) {
case 'Oranges':
console.log('Oranges are $0.59 a pound.');
break;
case 'Apples':
console.log('Apples are $0.32 a pound.');
break;
case 'Bananas':
console.log('Bananas are $0.48 a pound.');
break;
case 'Cherries':
console.log('Cherries are $3.00 a pound.');
break;
case 'Mangoes':
case 'Papayas':
console.log('Mangoes and papayas are $2.79 a pound.');
break;
default:
console.log('Sorry, we are out of ' + expr + '.');
}
console.log("Is there anything else you'd like?");