switch case assignment javascript code example
Example 1: js switch case
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Example 2: javascript switch assignment
var price = (function(color) {
switch(color) {
case 'red':
return 10;
case 'blue':
return 20;
default:
return 30;
}
})('blue');
console.log(price); // Will print 20