DEV Community

Pavithraarunachalam
Pavithraarunachalam

Posted on

Today Learned in Java Script:AND, OR in programming

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
Enter fullscreen mode Exit fullscreen mode

Example:

let age = 25;
if (age > 18 && age < 30) {
  console.log("You are in your twenties.");
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Example:

let isWeekend = true;
let isHoliday = false;

if (isWeekend || isHoliday) {
  console.log("You can relax today.");
}
Enter fullscreen mode Exit fullscreen mode

This will print "You can relax today." because isWeekend is true.


Top comments (0)