To check the condition in JavaScript, if the condition is true, the code inside the if braces will execute.
If the condition is not true, it goes to the next and checks the condition. If that condition is true, then the code inside the elseif braces runs.
If no condition is true, then the code inside the else braces runs.
Syntax:
if (condition1) {
// code to execute if condition1 is true
} elseif (condition2) {
// code to execute if condition2 is true
} else {
// code to execute if no conditions are true
}
Example:
let number = 15;
if (number > 20) {
console.log("Number is bigger than 20");
} else if (number > 10) {
console.log("Number is bigger than 10 but less than or equal to 20");
} else {
console.log("Number is 10 or less");
}
Output:
