JavaScript Basic
What are the differences between ==, ===, and Object.is() in JavaScript?
Differences Between ==, ===, and Object.is()
== (Loose Equality)
Performs type coercion before comparing:
0 == false // true (false converts to 0)
'' == false // true
null == undefined // true
1 == '1' // true ('1' converts to 1)
=== (Strict Equality)
No type coercion — both type and value must be identical:
0 === false // false (different types)
1 === '1' // false (different types)
null === undefined // false (different types)
NaN === NaN // false (special NaN behavior)
Object.is()
Behaves like === but fixes two edge cases:
Object.is(NaN, NaN) // true (=== gives false)
Object.is(+0, -0) // false (=== gives true)
Object.is(1, 1) // true
Object.is(null, null) // true
Summary
| Comparison | == |
=== |
Object.is() |
|---|---|---|---|
| Type coercion | ✅ Yes | ❌ No | ❌ No |
NaN vs NaN |
false | false | true |
+0 vs -0 |
true | true | false |
Always prefer
===. UseObject.is()only for preciseNaNand±0handling.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
