In JavaScript, AND and OR operations are used to control logic flow and decision-making. Here's a breakdown of how to use them:
Logical AND (&&)
Returns true only if both operands are true.
Syntax:
condition1 && condition2
Example:
let age = 25;
if (age > 18 && age < 30) {
console.log("You are in your twenties.");
}
This will print "You are in your twenties." because both conditions are true.
Logical OR (||)
Returns true if at least one operand is true.
Syntax:
condition1 || condition2
Example:
let isWeekend = true;
let isHoliday = false;
if (isWeekend || isHoliday) {
console.log("You can relax today.");
}
This will print "You can relax today." because
isWeekendistrue.
Top comments (0)