Quiz Entry - updated: 2026.07.05
What is the difference between == and === in JavaScript?
== compares values after converting types, while === compares both value and type with no conversion — and === is the one you should use.
Both operators ask "are these equal?", but they differ in how strict they are:
==(loose equality) first coerces the two values to a common type, then compares. So5 == '5'istrue, because the string'5'becomes the number5.===(strict equality) compares value and type, with no coercion.5 === '5'isfalse, because a number is not a string.
5 == '5' // true — '5' coerced to number 5
5 === '5' // false — different types
0 == false // true — false coerced to 0
0 === false // false — number vs boolean
null == undefined // true — a special loose-equality rule
null === undefined // false — different types
Loose == has a handful of surprising rules (like the ones above) that quietly cause bugs. The remedy is simple: default to === so comparisons mean exactly what they say. The same distinction applies to inequality: != (loose) versus !== (strict) — prefer !==.
Go deeper:
javascript.info: Comparisons — how type conversion drives
==, plus the counterintuitivenull/undefinededge cases.