Answers for "Javascript Switch Syntax"

155

js switch case

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Posted by: Guest on February-21-2020
31

switch javascript

switch (a) {
    case 1:
        alert('case 1 executed');
        break;
    case 2:
        alert("case 2 executed");
        break;
   case 3:
        alert("case 3 executed");
        break;
    case 4:
        alert("case 4 executed");
        break;
    default:
        alert("default case executed");
}
Posted by: Guest on March-23-2020
78

javascript switch

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Posted by: Guest on July-31-2019
1

Javascript Switch Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}
Posted by: Guest on May-31-2021
0

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
Posted by: Guest on December-16-2020

Browse Popular Code Answers by Language