JavaScriptInterview preparation
Foundation·Concept·2 min read

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

Practice this question

Definition:

== is loose equality: it may convert values to compatible types before comparing them. === is strict equality: it compares without that conversion. Strict equality usually makes application checks easier to understand because strings, numbers and booleans are not silently treated as the same value.

Key points:

  • == may convert types: 5 == '5' is true.

  • === does not convert types: 5 === '5' is false.

  • Two separate objects are not equal even if their contents match.

  • null == undefined is true, but null === undefined is false.

  • NaN is not equal to itself with either operator; use Number.isNaN when that is the question.

Comparison:

ExpressionResultReason
5 == '5'trueLoose equality converts types
5 === '5'falseNumber and string differ
null == undefinedtrueSpecial loose-equality rule
{} === {}falseTwo different objects

Interview point:

  • Object equality compares identity, not matching properties; switching from == to === does not perform a deep comparison.
Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What is the difference between == and ===?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.