=== (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.
console.log(0 == '', 0 === '', '1' == 1, null == undefined, null === undefined, NaN === NaN);true false true true false falseUse === 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.
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')));no marks 0
city not given
trueTo 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.
