Scope, If-else Conditionals & Switch Case in JavaScript
we will use let instead of var
// let a = "u";
// {
// let a = "u6";
// console.log(a)
// } value given in a container or condition are local to that container
thus the above example is valid
const a = "This cannot be changed";the value of a constant variable can not changed
if-else statement
// if(age>18){
// console.log("You can drink water");
// }
// else if(age==2){
// console.log("Age is 2")
// }
// else if(age==5){
// console.log("Age is 5")
// }
// else{
// console.log("You can drink Cold Drink");
// }this is the example of if else condition
switch
const cups = 47;
switch (cups) {
case 4:
console.log("The value of cups is 4")
break;
case 41:
console.log("The value of cups is 41")
break;
case 42:
console.log("The value of cups is 42")
break;
case 43:
console.log("The value of cups is 43")
break;
default:
console.log("The value of cups is none of 4, 41, 42, 43")
break;
}this is how we use switch statement
Comments
Post a Comment