switch on js code example
Example 1: js switch case
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 2: how to use switch case in javascript
switch (expression) {
case value1:
[break;]
case value2:
[break;]
...
case valueN:
[break;]
[default:
[break;]]
}
Example 3: switch i javascript
const expr = 'Papayas';
switch (expr) {
case 'Oranges':
console.log('Oranges are $0.59 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}.`);
}