JavaScript · The language round

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

EasyequalitycoercionoperatorsUpdated Oct 2026
Quiz this track

Short answer

=== compares without type coercion: values must already have the same type. == applies abstract equality coercion, which makes it powerful in a few cases and surprising in many.

The short interview answer is that === checks type and value, while == converts operands to a common type before comparing. The follow-up is whether there is ever a good reason to use ==.

js
0 == false; // true
0 === false; // false

"" == false; // true
"" === false; // false

null == undefined; // true
null === undefined; // false

NaN === NaN; // false
Object.is(NaN, NaN); // true

The coercion rules worth knowing

  • If the types differ, == converts booleans and strings to numbers, then compares.
  • null == undefined is true, but neither equals 0, "" or false under ==.
  • Objects are converted with ToPrimitive before comparison, which is why [] == false is true.
  • NaN is not equal to anything, including itself, under both == and ===.

The one idiomatic use of == is the null check: value == null matches both null and undefined and nothing else. Otherwise, prefer ===.

js
if (value == null) {
  // true for null or undefined
}

if (Object.is(value, NaN)) {
  // explicit NaN check
}

Common mistakes

  • Saying == always converts to a boolean. It converts to a common type, not necessarily boolean.
  • Using === for NaN and expecting true. Use Number.isNaN() or Object.is().
  • Treating Object.is() as identical to ===; it differs for NaN and signed zero.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1When would you intentionally use `==`?
  2. 2Why is `NaN === NaN` false?
  3. 3What is `Object.is()` and how does it differ from `===`?
  4. 4Why is `[] == false` true?

Say it in the interview

Triple equals compares type and value with no coercion. Double equals applies abstract equality coercion, so zero equals false and null equals undefined. I use triple equals by default because it makes types explicit. The one exception is a null check, where value == null cleanly matches both null and undefined. NaN is a separate case: it is not equal to itself under either operator.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live JavaScript mock interview and get scored feedback on depth, clarity and confidence.