only 7 "falsy" values in JS.
Last updated 2 years ago
Was this helpful?
JS ⟩ value ⟩ type ⟩ conversion ⟩ falsy
7 falsy values:(converts to false)
false, 0, 0n, null, undefined, NaN, "" (empty string).
false
0
0n
null
undefined
NaN
""
any other value is "truthy", and converts to true.
every value is either truthy or falsy❗
all objects are (convert to true).
(s) that expect operands will work with an operand of any type❗
Boolean
arr.filter() - remove falsy values.
'0' == false // true❗️ if ('0') console.log('hi') // hi (⭐️ '0' is truthy❗️) '0' === false // false❗️ // facts about empty array [] ==
sitepoint ⟩ Truthy and Falsy: When All is Not Equal in JavaScript
In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by itself?