Menu

== vs === in JavaScript: Loose Equality vs Strict Equality vs Object.is() Explained (Comparison Table and Tested Examples)
📰

== vs === in JavaScript: Loose Equality vs Strict Equality vs Object.is() Explained (Comparison Table and Tested Examples)

DEV Community: typescript·Mahir Faysal·9 days ago
#2hVDaGcj
#devtotypescript#devto#dev#false#true
Reading 0:00
15s threshold

In JavaScript, === (strict equality) returns true only when both values have the same type and the same value, with no conversion. == (loose equality) first converts the two values to a common type and then compares them, so "1" == 1 is true but "1" === 1 is false . Use === by default. The one common exception is value == null , which checks for both null and undefined in one go.

There's also a third option, Object.is() , which behaves like === except for two edge cases: NaN and -0 . I'll cover all three, plus how arrays, switch , ESLint and TypeScript fit in.

Every result below comes from scripts I ran on Node.js 24.22.1, with the truth table re-checked on Node.js 18.20.8, 22.23.4 and 26.11.1 (identical output on all four), plus Chrome 156 for the browser examples, TypeScript 7.0.2 and ESLint 10.14.0.

In this guide:

Quick comparison: ==, === and Object.is()

How === (strict equality) works

How == (loose equality) works

Tested truth table: == vs ===

The strangest == results, explained

NaN, -0 and…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.