easyFrontend EngineerSaaS
What is the difference between ==, ===, and Object.is() in JavaScript? When does it matter in production code?
Posted 18/04/2026
by Mehedy Hasan Ador
Question Details
An interviewer at a SaaS company asked:
> "We had a bug where a filter condition
> "We had a bug where a filter condition
if (value == null) was catching undefined AND null, but the developer intended to only catch null. This caused records to be hidden incorrectly. Can you explain the coercion rules and when to use each equality check?"Suggested Solution
Equality Comparison Types
== (Abstract Equality — Type Coercion)
null == undefined // true
0 == false // true
"" == false // true
"1" == 1 // true
[] == false // true
[] == ![] // true (!)
JavaScript converts types before comparison using the Abstract Equality Comparison Algorithm (ES spec §7.2.15). This leads to unexpected results.=== (Strict Equality — No Coercion)
null === undefined // false
0 === false // false
"1" === 1 // false
NaN === NaN // false (!)
+0 === -0 // true (!)
No type conversion, but has two edge cases: NaN and signed zeros.Object.is() (SameValue — Most Precise)
Object.is(NaN, NaN) // true
Object.is(+0, -0) // false
Object.is(null, null) // true
Production Impact
nullundefined0""false== null=== null=== undefinedBest Practices
1. Always use=== except for one valid case:2.
== null is the ONLY acceptable loose comparison — it checks both null AND undefined (useful for optional parameters):function process(data: string | null | undefined) {
if (data == null) return; // catches both null and undefined
}
3. Object.is() for NaN checks: Object.is(value, NaN) instead of Number.isNaN() polyfill scenarios