JavaScript - Logical Operators

Overview

Estimated time: 15–25 minutes

Combine predicates with logical AND/OR and negate with NOT. Understand short-circuiting and truthy/falsy.

Learning Objectives

  • Use &&, ||, and ! safely.
  • Predict short-circuit behavior.

Prerequisites

Examples

const ok = (x > 0 && y > 0);
const fallback = user.name || 'Anonymous';
const notAuth = !isAuthenticated;

Short-circuiting

// Right side only evaluated if needed
condition && doIfTrue();
condition || doIfFalse();

Common Pitfalls

  • || treats 0 and '' as falsy; use ?? to only treat null/undefined as missing.