Typorithm · easy

== vs ===

equality-coercioninterview-questionsequalitycoercionstrict-equality
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn == vs ===

0%

JS Gotchas

== coerces both operands before comparing, producing surprises like 0 == "". === compares type and value with no conversion. null == undefined is true, and NaN is never equal to itself.

Loose equality (==) converts the operands to a common type before comparing, so 0 == "" and 0 == false are both true even though the values look different.

Strict equality (===) compares type and value directly with no conversion, so 0 === "" is false — that is why teams default to ===.

Two special cases bite everyone: null == undefined is true (they are loosely equal only to each other), and NaN === NaN is false because NaN is never equal to itself.

01

== coerces before comparing; === does not.

02

0 == "" is true but 0 === "" is false.

03

null == undefined is true; NaN === NaN is false.

0 == ""          // true  — both coerce to falsy
0 === ""         // false — different types
null == undefined // true  — loose equality
NaN === NaN      // false — NaN never equals itself

Read the implementation

Connect each part of the code to the concept before you type.

1. Loose equality coerces

== converts both sides before comparing, so 0 and "" both become 0 and match.

0 == ""          // true  — both coerce to falsy

2. Strict equality

=== compares type and value with no conversion, so a number is never equal to a string.

0 === ""         // false — different types

3. null == undefined

Loose equality treats null and undefined as equal to each other (and to nothing else).

null == undefined // true  — loose equality

4. NaN is unique

NaN is the only value not equal to itself; use Number.isNaN to test for it.

NaN === NaN      // false — NaN never equals itself

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

== vs ===: Lesson & Practice · Typorithm | ApplyDjinn