Written by Rahul · Frontend Engineer at Google · Updated 2025
Short answer: always use ===. Long answer: understanding why will save you from some of the most bizarre bugs in JavaScript.
The Core Difference
===(Strict Equality) — Compares value AND type. No conversions.==(Loose Equality) — Converts types first, then compares. Chaos follows.
The Type Coercion Madness
Here's the famous table of == insanity:
The Only Exception — null Checking
There's exactly ONE case where == is acceptable:
Real Production Bugs from ==
Bug 1: Form Validation
Bug 2: API Response Checking
Best Practices
- Always use
===and!==— no exceptions (ESLint rule:eqeqeq) - Convert types explicitly —
Number(str),String(num),Boolean(val) - Use nullish coalescing (
??) instead of== nullchecks - Enable ESLint — the
eqeqeqrule catches these automatically
Interview Tip
Know the [] == ![] example and be able to explain the coercion steps. Then say "in practice, I always use strict equality and let the linter enforce it." That shows both knowledge and pragmatism.