Logical Comparison

Combining comparisons.

Examples

AND Condition

Both conditions must be true.

let age = 20;
if (age > 18 && age < 30) {
    console.log("Young Adult");
}

OR Condition

Either condition must be true.

let day = "Sunday";
if (day === "Saturday" || day === "Sunday") {
    console.log("Weekend!");
}

Complex Logic

Combining AND and OR.

let age = 15;
let hasParentVar = true;
if (age > 18 || (age < 18 && hasParentVar)) {
    console.log("Allowed");
}

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.