Comparison & Logical in JavaScript
From the JavaScript cheat sheet · Operators · verified Jul 2026
Comparison & Logical
Comparing values and logical operations
javascript
// Comparison
5 == '5' // true (loose equality)
5 === '5' // false (strict equality)
5 != '5' // false
5 !== '5' // true
5 > 3 // true
5 >= 5 // true
5 < 3 // false
5 <= 5 // true
// Logical
true && false // false (AND)
true || false // true (OR)
!true // false (NOT)
// Short-circuit evaluation
const value = null || 'default'; // 'default'
condition && doSomething();💡 Always use === and !== to avoid type coercion surprises
⚡ Logical operators use short-circuit evaluation
📌 && returns first falsy or last truthy, || returns first truthy or last falsy
🔥 ?? (nullish coalescing) only checks for null/undefined, not all falsy values