hen your conditions become slightly more complex, you often need to combine multiple conditions together. That’s where logical operators in JavaScript are used.

They help you write smarter and more powerful conditional logic

What are Logical Operators in JavaScript?

Logical operators allow you to connect or modify conditions.

JavaScript provides three main logical operators:

  • &&  (AND)

  •  | | (OR)

  • ! (NOT)


AND Operator ( && )

The AND operator returns true only when both conditions are true.

JavaScript
1let age = 22;
2let hasID = true;
3
4if (age >= 18 && hasID) {
5 console.log("You can enter the club");
6}
7

OR Operator ( | | )

The OR operator returns true when at least one condition is true

JavaScript
1let isWeekend = true;
2let isHoliday = false;
3
4if (isWeekend || isHoliday) {
5 console.log("You can relax today");
6}
7

NOT Operator ( ! )

The NOT operator reverses the Boolean value.

JavaScript
1let isLoggedIn = false;
2
3if (!isLoggedIn) {
4 console.log("Please login to continue");
5}
6

Logical operators are essential for building real-world features like authentication, form validation, filters, and access control.