Skip to content
UniCircle
TipEngineeringB.Tech / B.E., BCA, MCA

== versus === and truthy values in JavaScript

Why loose equality surprises people, the short list of falsy values, and safe ways to check for missing values with ?? and ?.

By UniCircle team1 min readPublished 22 Oct 2026Undergraduate

=== (strict equality) compares type and value. == (loose equality) first converts the two sides to a common type, and the rules for that are easy to forget.

JavaScript
console.log(0 == '', 0 === '', '1' == 1, null == undefined, null === undefined, NaN === NaN);
text
true false true true false false

Use === and !== everywhere. The only common exception is x == null, which is true for both null and undefined.

The falsy values

Only these are falsy; everything else, including '0', 'false', [] and {}, is truthy: false, 0, -0, 0n, '' (empty string), null, undefined and NaN.

?? and ?. instead of ||

|| treats 0 and '' as missing, which is often wrong. ?? only replaces null and undefined. ?. stops safely when something is missing.

JavaScript
const student = { name: 'Asha', marks: 0, address: null };
console.log(student.marks || 'no marks', student.marks ?? 'no marks');
console.log(student.address?.city ?? 'city not given');
console.log(Number.isNaN(Number('abc')));
text
no marks 0
city not given
true

To check for NaN, use Number.isNaN(x), because NaN is the one value not equal to itself.

#javascript#equality#truthy#nullish

Sources and further reading

Written by the UniCircle team, checked by an editor on 22 Oct 2026. It is not official policy of any university. Exam patterns and rules change; confirm dates and rules on the official website.

Keep reading