Falsy values are values considered in JavaScript falsy in context of conditions. There are 6 of them and they are undefined
, null
, NaN
, 0
, ""
(empty string) and false
.
It means converting it to Boolean
will end with getting false
.
let counter = 0; if (0 || "" || undefined || null || false || NaN) { counter++; } console.info(counter); // 0 console.info([0, "", undefined, null, false, NaN].map(Boolean)); // [false, false, false, false, false, false]
Be careful - it doesn't mean all of these values are equal to false
console.info(0 == false); // true console.info("" == false); // true console.info(false == false); // true console.info(NaN == false); // false console.info(undefined == false); // false console.info(null == false); // false