js switch case
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
js switch case
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
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"
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");
}
Switch Case Statement in JavaScript
var a=3;
switch(a)
{
case 1:
console.log("Value of a is 1");
break;
case 2: // grouped three cases
case 3:
case 4:
console.log("Value of between 2 and 4");
break;
default:
console.log("Value of a not matched");
break;
}
// Output: Value of between 2 and 4
Switch Case Statement in JavaScript
var day = new Date();
switch(day.getDay())
{
case 0:
console.log("Today is Sunday");
break;
case 1:
console.log("Today is Monday");
break;
case 2:
console.log("Today is Tuesday");
break;
case 3:
console.log("Today is Wednesday");
break;
case 4:
console.log("Today is Thursday");
break;
case 5:
console.log("Today is Friday");
break;
case 6:
console.log("Today is Saturday");
break;
default:
console.log("No Information Found");
break;
}
// Output : Today is Monday
Switch Case Statement in JavaScript
switch(x){
case value1: // if x === value1
...
break;
case value2: // if x === value2
...
break;
default: // if x not match
...
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us