switch case in js example

Example 1: js switch case

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

Example 2: js switch

var myvalue='val1';//or other values; val2 val3 valx
switch(myvalue) {
  case 'val1':
      	console.log('var myvalue is '+ myvalue);
    	//other code ...
    break;
  case 'val2':
    	console.log('var myvalue is '+ myvalue);
    	//other code ...
    break;
  default:
    	// when all the other values not covered with cases above
    	// other code ...
}

Example 3: 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?");