ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

== vs === — what's the difference?

Quick answer

`===` compares value and type with no coercion; `==` coerces operands to a common type first.

In detail

`===` (strict) returns true only when type and value match. `==` (loose) applies coercion, producing surprises like `0 == ''`, `false == '0'`, and `null == undefined` all being true. Always use `===`; the one useful `==` idiom is `x == null` to catch both null and undefined.

0 == "";          // true
0 == "0";         // true
"" == "0";        // false
null == undefined;// true
if (x == null) { /* null OR undefined */ }

Why interviewers ask this: Reveals understanding of coercion, a top bug source.

Common follow-up questions

  • What does [] == ![] return?

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →