Falsy

A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context.

JavaScript uses type conversion to coerce any value to a Boolean in contexts that require it, such as conditionals and loops.

There are 8 falsy values:

false The keyword false
0 The number zero
-0 The number negative zero
0n BigInt, when used as a boolean, follows the same rule as a Number. 0n is falsy.
""

Empty string value

null null - the absence of any value
undefined undefined - the primitive value
NaN NaN - not a number

document.all has been used for browser detection in the past and the HTML specification defines a willful violation of the ECMAScript standard here by making it falsy even though it is an object, to keep compatibility with legacy code (if (document.all) { // Internet Explorer code here (except IE11) } or using document.all without checking its presence first: document.all.foo).

Examples

Examples of falsy values in JavaScript (which are coerced to false in Boolean contexts, and thus bypass the if block):

if (false)
if (null)
if (undefined)
if (0)
if (-0)
if (0n)
if (NaN)
if ("")

The logical AND operator, &&

If the first object is falsy, it returns that object

false && "dog"
// ↪ false

0 && "dog"
// ↪ 0

Specifications

Specification
ECMAScript (ECMA-262)
The definition of 'ToBoolean abstract operation' in that specification.

Learn more