Course contentsShow
← JavaScript
Lesson 222 of 2,7236. Booleans and ConditionalsFree lesson

Combining Multiple Logical Operators

Chain &&, ||, and ! together while understanding evaluation order and precedence.

Combining Multiple Logical Operators

You'll learn how to chain &&, ||, and ! together in a single expression and understand which operators evaluate first.

The Core Idea

Just like math has order of operations (multiplication before addition), JavaScript's logical operators also have precedence rules. When you combine &&, ||, and ! in one expression, JavaScript evaluates them in a specific order:

  1. ! (NOT) — highest precedence, evaluated first
  2. && (AND) — evaluated second
  3. || (OR) — lowest precedence, evaluated last

Think of it like this: negations happen immediately, then "ands" group together, and finally "ors" connect everything.

How It Works in Practice

let result = !false && true || false;
// Step 1: !false → true
// Step 2: true && true → true
// Step 3: true || false → true
console.log(result); // true

You can use parentheses to override the default order, just like in math:

let a = true || false && false;
// && happens first: false && false → false
// Then ||: true || false → true
console.log(a); // true

let b = (true || false) && false;
// () forces ||: true || false → true
// Then &&: true && false → false
console.log(b); // false

Why This Matters

Complex conditions are common in real code:

let isLoggedIn = true;
let hasPermission = false;
let isAdmin = true;

let canAccess = isLoggedIn && (hasPermission || isAdmin);
// isLoggedIn && (false || true)
// isLoggedIn && true
// true

Key Takeaway: When combining logical operators, ! evaluates first, then &&, then ||. Use parentheses to make your intent clear and override default precedence.