Programming

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

Short answer

== compares two values after converting them to the same type if needed ("loose equality"), while === compares both value and type without any conversion ("strict equality").

This is one of the most common sources of unexpected behavior for developers new to JavaScript, because == can produce surprising results.

Examples with == (loose equality)

0 == false        // true — false converts to 0
"5" == 5          // true — "5" converts to number 5
null == undefined // true — special case

Examples with === (strict equality)

0 === false        // false — different types
"5" === 5          // false — different types
null === undefined // false — different types

Because == performs implicit type conversion before comparing, it can produce results that don't match intuition. Most modern JavaScript style guides recommend always using === (and its counterpart !==) to avoid these surprises, reserving == only for the rare cases where the conversion behavior is genuinely intended.

Last reviewed: September 2026