A nested if condition is an if statement inside another if statement.
It allows you to test multiple conditions sequentially.
if (condition1) {
// code if condition1 is true
if (condition2) {
// code if condition2 is also true
}
} else {
// code if condition1 is false
}
let age = 20;
let score = 85;
if (age >= 18) {
if (score >= 80) {
console.log("Adult with high score");
} else {
console.log("Adult with low score");
}
} else {
console.log("Not an adult");
}
Click the button to see nested if conditions in action: