DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. == vs === in JavaScript — Why Triple Equals Wins Every Time
XLinkedInReddit
MediumFrontend Engineering

== vs === in JavaScript — Why Triple Equals Wins Every Time

D
DevPrep Team
February 9, 2026·3 min read·0
Table of Contents
  • The Core Difference
  • The Type Coercion Madness
  • The Only Exception — null Checking
  • Real Production Bugs from ==
  • Bug 1: Form Validation
  • Bug 2: API Response Checking
  • Best Practices
  • Interview Tip

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.
// Strict equality — predictable
1 === 1        // true
1 === "1"      // false (number vs string)
null === undefined // false

// Loose equality — JavaScript goes wild
1 == "1"       // true  (string "1" → number 1)
"" == false    // true  (both → 0)
null == undefined // true  (special rule)
[] == false    // true  ([] → "" → 0, false → 0)
"0" == false   // true  ("0" → 0, false → 0)
"" == 0        // true  ("" → 0)

The Type Coercion Madness

Here's the famous table of == insanity:

[] == ![]      // true  — yes, really
[] == false    // true
"" == false    // true
0 == false     // true
0 == ""        // true
0 == "0"       // true
"" == "0"      // false — wait, what?

// The logic:
// [] == ![]
// [] == false    (! converts [] to boolean true, then negates to false)
// "" == false    ([] converts to "")
// 0 == 0         ("" and false both convert to 0)
// true!

The Only Exception — null Checking

There's exactly ONE case where == is acceptable:

// Check for null OR undefined in one shot
if (value == null) {
  // This catches both null and undefined
  // Equivalent to: value === null || value === undefined
}

// This is used in some codebases, but I prefer being explicit:
if (value === null || value === undefined) { ... }
// Or even better in modern JS:
if (value ?? "default") { ... }

Real Production Bugs from ==

Bug 1: Form Validation

const userInput = document.getElementById("age").value; // Always a string!

// ❌ This "works" but is misleading
if (userInput == 18) { // "18" == 18 is true due to coercion
  allowAccess();
}

// What happens when input is empty?
"" == 0  // true! Empty field passes numeric checks

// ✅ Parse explicitly
const age = parseInt(userInput, 10);
if (age === 18) {
  allowAccess();
}

Bug 2: API Response Checking

const response = await fetch("/api/count");
const data = await response.json(); // { count: 0 }

// ❌ Loose equality treats 0 as falsy
if (data.count == false) {
  showEmptyState(); // Shows empty state when count is 0!
}

// ✅ Be explicit
if (data.count === 0) {
  showEmptyState();
}

Best Practices

  1. Always use === and !== — no exceptions (ESLint rule: eqeqeq)
  2. Convert types explicitly — Number(str), String(num), Boolean(val)
  3. Use nullish coalescing (??) instead of == null checks
  4. Enable ESLint — the eqeqeq rule 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.

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • The Core Difference
  • The Type Coercion Madness
  • The Only Exception — null Checking
  • Real Production Bugs from ==
  • Bug 1: Form Validation
  • Bug 2: API Response Checking
  • Best Practices
  • Interview Tip

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.