Back to Content

Falsy

files/en-us/glossary/falsy/index.md

latest3.4 KB
Original Source
<!-- cSpell:ignore falsey -->

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

{{Glossary("JavaScript")}} uses {{Glossary("Type_Conversion", "type conversion")}} to coerce any value to a Boolean in contexts that require it, such as {{Glossary("Conditional", "conditionals")}} and {{Glossary("Loop", "loops")}}.

The following table provides a complete list of JavaScript falsy values:

ValueTypeDescription
{{Glossary("null")}}NullThe keyword null — the absence of any value.
{{Glossary("undefined")}}Undefinedundefined — the primitive value.
falseBooleanThe keyword false.
{{Glossary("NaN")}}NumberNaN — not a number.
0NumberThe {{jsxref("Number")}} zero, also including 0.0, 0x0, etc.
-0NumberThe {{jsxref("Number")}} negative zero, also including -0.0, -0x0, etc.
0nBigIntThe {{jsxref("BigInt")}} zero, also including 0x0n, etc. Note that there is no {{jsxref("BigInt")}} negative zero — the negation of 0n is 0n.
""StringEmpty string value, also including '' and ``.
{{domxref("document.all")}}ObjectThe only falsy object in JavaScript is the built-in {{domxref("document.all")}}.

The values null and undefined are also {{Glossary("nullish")}}.

Examples

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

js
if (false) {
  // Not reachable
}

if (null) {
  // Not reachable
}

if (undefined) {
  // Not reachable
}

if (0) {
  // Not reachable
}

if (-0) {
  // Not reachable
}

if (0n) {
  // Not reachable
}

if (NaN) {
  // Not reachable
}

if ("") {
  // Not reachable
}

The logical AND operator, &&

If the first object is falsy, it returns that object:

js
console.log(false && "dog");
// ↪ false

console.log(0 && "dog");
// ↪ 0

See also

  • Related glossary terms:
    • {{Glossary("Truthy")}}
    • {{Glossary("Type_coercion", "Coercion")}}
    • {{Glossary("Boolean")}}
  • Boolean coercion