Skip to solution
easyFrontend

What is the difference between == and ===?

160 views
01

Understand the problem

Question presented to candidate: "What's the difference between == and === in JavaScript, and why do most style guides tell you to always use ===?"

What a strong answer should cover:

  • 📌 Interview term: loose equality (==) — compares two values after converting them to a common type when their types differ. Verified directly: 1 == "1" is true because the string is coerced to a number first.
  • 📌 Interview term: strict equality (===) — compares both type and value, with no coercion at all. Verified: 1 === "1" is false because a number and a string are never equal under ===, regardless of their values.
  • A precise answer names the coercion rules that make == unpredictable: null == undefined is true (a special-cased pair — they equal each other and nothing else under ==), 0 == false is true, and "" == false is true — verified directly.
  • 📌 Interview term: the classic gotcha[] == ![] evaluates to true. Verified by tracing it step by step: ![] evaluates first (an empty array is truthy, so ! of it is false), leaving [] == false, which coerces the array to a primitive ("") and then to a number (0), matching false's own 0.
  • NaN == NaN is false under both operators — coercion never makes NaN equal to anything, including itself — verified directly.

Clarifying questions expected:

  • None — this is a definitional/comparison question; the strong move is naming the coercion mechanism precisely rather than just "== is looser."

Code / implementation expected: Optional — walking through 2-3 concrete coercion examples (including the null == undefined special case) demonstrates real understanding better than reciting the rule from memory.

equality
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interviews. Difficulty: Easy

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every comparison below was actually run in Node — not recited from memory.

1. Why This

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal coercion cases for == vs ===, including the [] == ![] gotcha traced step by step
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 40 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track