Skip to the workspace
Pebellslearn by building
Equality Comparisons  ›  Lesson

Strict Equality (===)

=== 12 min

javascript / Strict Equality (===)

Explore each scene at your own pace.

01 · Strict Equality (===)

Strict Equality (===)

Strict Equality (===)

Strict equality (===) compares values without converting between types. Objects are equal only when both operands refer to the same object.

The number 4 and the text "4" are different values for this comparison.

See the mechanism

Walk through the modelStrict Equality (===)Authored snapshots of the example; use Run below to test the code.
Stateleft: number 4
Stateright: string "4"
The displayed characters resemble each other, but their types differ.
1 of 3

Follow one example

javascript

The first result is false because the operand types differ. The second is true because both numbers have the same value. false and 0 remain different. Strict equality is a good default comparison; it does not validate or normalize data for you. NaN is not equal to itself with ===.

Predict, change and check

Predict: If a reading-time input supplies "4", can comparing it directly with numeric 4 succeed?

Test your explanation: Compare "4" with "4", then compare it with 4. Keep type conversion as a separate deliberate step in later lessons.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Identity and type both matter

Strict equality does not coerce a numeric string to a number, and it does not recursively compare object fields. Two references to the same object compare equal; separately constructed records compare unequal. A failed equality check can therefore indicate a representation mismatch or an identity mismatch.

NaN is unequal to itself under ===, while +0 and -0 compare equal. Those are defined numeric cases, not a reason to replace every equality check with Object.is. Choose the rule required by the data and test the relevant boundaries rather than changing operators until a single example passes.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.