Nested - if
let mark=40;
let att=77;
if(mark>=35){
if(att>75){
console.log("Eligible for Trip");
}
}else{
console.log("Not Eligible");
}
o/p - Eligible for Trip
Ternary Operator
Syntax
condition ? true : false ;
Switch
The switch case statement in JavaScript is used to execute different blocks of code based on the value of an expression. It is often preferred over multiple if / else if statements when checking a single variable against many possible values, as it improves readability and maintainability.
let switchNo = 2;
switch(switchNo)
{
case 1:
console.log("fan");
break;
case 2:
console.log("light");
break;
case 3:
console.log("ac");
break;
default:
console.log("enter valid input");
}
o/p - light
Undefined
if the input value is not in the list or case means it will show as undefined.
default
it is used for, if the user or someone gives wrong input value means the default case will be shown.
While loop
It keeps looping until the condition is true or false.
Top comments (0)