only 7 "falsy" values in JS.
Last updated 2 years ago
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 truthy (convert to true).
operator(s) that expect boolean 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 [] == ![] // true❗️ [] == [] // false❗️ Boolean([]) // true Boolean(![]) // false❗️
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?