In programming, truthiness or falsiness is that quality of those boolean expressions which don't resolve to an actual boolean value, but which nevertheless get interpreted as a boolean result.

In the case of C, any expression that evaluates to zero is interpreted to be false. In Javascript, the expression value in

if(value) {
}

will evaluate to true if value is not:

null
undefined
NaN
empty string ("")
0
false

See Also
Is there a standard function to check for null, undefined, or blank variables in JavaScript?

Answer from Robert Harvey on Stack Exchange
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Glossary โ€บ Falsy
Falsy - Glossary | MDN
A falsy (sometimes written falsey) ... it, such as conditionals and loops. The following table provides a complete list of JavaScript falsy values: The values null ......
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ falsy-values-in-javascript
Falsy Values in JavaScript
December 14, 2019 - Description A falsy value is something which evaluates to FALSE, for instance when checking a variable. There are only six falsey values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false of course. Checking for falsy values ...
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ null
null - JavaScript | MDN
Like undefined, null is treated as falsy for boolean operations, and nullish for nullish coalescing and optional chaining. The typeof null result is "object". This is a bug in JavaScript that cannot be fixed due to backward compatibility.
Top answer
1 of 5
24

In programming, truthiness or falsiness is that quality of those boolean expressions which don't resolve to an actual boolean value, but which nevertheless get interpreted as a boolean result.

In the case of C, any expression that evaluates to zero is interpreted to be false. In Javascript, the expression value in

if(value) {
}

will evaluate to true if value is not:

null
undefined
NaN
empty string ("")
0
false

See Also
Is there a standard function to check for null, undefined, or blank variables in JavaScript?

2 of 5
9

The set of "truthy" and "falsey" values in JavaScript comes from the ToBoolean abstract operation defined in the ECMAScript spec, which is used when coercing a value to a boolean:

+--------------------------------------------------------------------------+
| Argument Type | Result                                                   |
|---------------+----------------------------------------------------------|
| Undefined     | false                                                    |
|---------------+----------------------------------------------------------|
| Null          | false                                                    |
|---------------+----------------------------------------------------------|
| Boolean       | The result equals the input argument (no conversion).    |
|---------------+----------------------------------------------------------|
| Number        | The result is false if the argument is +0, โˆ’0, or NaN;   |
|               | otherwise the result is true.                            |
|---------------+----------------------------------------------------------|
| String        | The result is false if the argument is the empty String  |
|               | (its length is zero); otherwise the result is true.      |
|---------------+----------------------------------------------------------|
| Object        | true                                                     |
+--------------------------------------------------------------------------+

From this table, we can see that null and undefined are both coerced to false in a boolean context. However, your fields.length === 0 does not map generally onto a false value. If fields.length is a string, then it will be treated as false (because a zero-length string is false), but if it is an object (including an array) it will coerce to true.

If fields should be a string, then !fields is a sufficient predicate. If fields is an array, your best check might be:

if (!fields || fields.length === 0)
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-are-falsy-values-and-truthy-in-javascript
What are falsy values and truthy in JavaScript?
So, if you want to check whether a variable initialized with null has been initialized with a value, null will return false. ... The first part will log no, not yet while the second part will log yes, initialized. undefined is assigned to a ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ can someone explain this more? how can a value become true and false at the same time?
r/learnjavascript on Reddit: Can someone explain this more? How can a value become true and false at the same time?
June 23, 2022 - They are the absence of a string, or any other value. ... Good way to remember is that falsy values in JavaScript are: false, null, undefined, 0, "" (empty string), NaN (not a number). Anything else evaluates to true.
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ falsy
What is "Falsy" in JavaScript? - Mastering JS
These 7 values are the only falsy values in JavaScript. Any value that is not falsy is truthy. In particular, a non-null object is always truthy, even if its valueOf() function returns a falsy value.
Find elsewhere
Top answer
1 of 4
456

Falsey values in JavaScript

  • false
  • Zero of Number type: 0 and also -0, 0.0, and hex form 0x0 (thanks RBT)
  • Zero of BigInt type: 0n and 0x0n (new in 2020, thanks GetMeARemoteJob)
  • "", '' and `` - strings of length 0
  • null
  • undefined
  • NaN
  • document.all (in HTML browsers only)
    • This is a weird one. document.all is a falsey object, with typeof as undefined. It was a Microsoft-proprietory function in IE before IE11, and was added to the HTML spec as a "willful violation of the JavaScript specification" so that sites written for IE wouldn't break on trying to access, for example, document.all.something; it's falsy because if (document.all) used to be a popular way to detect IE, before conditional comments. See Why is document.all falsy? for details

"Falsey" simply means that JavaScript's internal ToBoolean function returns false. ToBoolean underlies !value, value ? ... : ...; and if (value). Here's its official specification (2020 working draft) (the only changes since the very first ECMAscript specification in 1997 are the addition of ES6's Symbols, which are always truthy, and BigInt, mentioned above:

Argument type Result
Undefined Return false.
Null Return false.
Boolean Return argument.
Number If argument is +0, -0, or NaN, return false; otherwise return true.
String If argument is the empty String (its length is zero), return false; otherwise return true.
BigInt If argument is 0n, return false; otherwise return true.
Symbol Return true.
Object Return true.

Comparisons with == (loose equality)

It's worth talking about falsy values' loose comparisons with ==, which uses ToNumber() and can cause some confusion due to the underlying differences. They effectively form three groups:

  • false, 0, -0, "", '' all match each other with ==
    • e.g. false == "", '' == 0 and therefore 4/2 - 2 == 'some string'.slice(11);
  • null, undefined match with ==
    • e.g. null == undefined but undefined != false
    • It's also worth mentioning that while typeof null returns 'object', null is not an object, this is a longstanding bug/quirk that was not fixed in order to maintain compatibility. It's not a true object, and objects are truthy (except for that "wilful violation" document.all when Javascript is implemented in HTML)
  • NaN doesn't match anything, with == or ===, not even itself
    • e.g. NaN != NaN, NaN !== NaN, NaN != false, NaN != null

With "strict equality" (===), there are no such groupings. Only false === false.

This is one of the reasons why many developers and many style guides (e.g. standardjs) prefer === and almost never use ==.


Truthy values that actually == false

"Truthy" simply means that JavaScript's internal ToBoolean function returns true. A quirk of Javascript to be aware of (and another good reason to prefer === over ==): it is possible for a value to be truthy (ToBoolean returns true), but also == false.

You might think if (value && value == false) alert('Huh?') is a logical impossibility that couldn't happen, but it will, for:

  • "0" and '0' - they're non-empty strings, which are truthy, but Javascript's == matches numbers with equivalent strings (e.g. 42 == "42"). Since 0 == false, if "0" == 0, "0" == false.
  • new Number(0) and new Boolean(false) - they're objects, which are truthy, but == sees their values, which == false.
  • 0 .toExponential(); - an object with a numerical value equivalent to 0
  • Any similar constructions that give you a false-equaling value wrapped in a type that is truthy
  • [], [[]] and [0] (thanks cloudfeet for the JavaScript Equality Table link)

Some more truthy values

These are just a few values that some people might expect to be falsey, but are actually truthy.

  • -1 and all non-zero negative numbers

  • ' ', " ", "false", 'null'... all non-empty strings, including strings that are just whitespace

  • Anything from typeof, which always returns a non-empty string, for example:

    • typeof null (returns a string 'object' due to a longstanding bug/quirk)
    • typeof undefined (returns a string 'undefined')
  • Any object (except that "wilful violation" document.all in browsers). Remember that null isn't really an object, despite typeof suggesting otherwise. Examples:

    • {}
    • []
    • function(){} or () => {} (any function, including empty functions)
    • Error and any instance of Error
    • Any regular expression
    • Anything created with new (including new Number(0) and new Boolean(false))
  • Any Symbol

true, 1, "1" and [1] return true when compared to each other with ==.

2 of 4
4

Don't forget about the non-empty string "false" which evaluates to true

๐ŸŒ
Medium
medium.com โ€บ programming-essentials โ€บ what-are-the-differences-between-falsy-and-nullish-values-7d0c1d81a20e
What Are the Differences Between Falsy and Nullish Values? | by Cristian Salcescu | Frontend Essentials | Medium
December 31, 2021 - ... This article looks at the key characteristics of the nullish and falsy values and points the differences between them. 0, 0n, '', false, NaN, null and undefined are falsy values. All the other values are truthy.
๐ŸŒ
Fridoverweij
library.fridoverweij.com โ€บ docs โ€บ jstutorial โ€บ data_type_conversion2.html
JavaScript Tutorial โ€“ Falsy, truthy & nullish
So, statement if(someVar) skips execution for any falsy value of someVar. If you want to check for specific falsy (or truthy) values, you can use the strict equality operators. let someVar = null; if (someVar) { console.log("This does NOT get returned."); } // null is falsy, thus the condition ...
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ falsy-values-in-javascript
What Values Does JavaScript Consider Falsy? - Scaler Topics
December 20, 2022 - The javascript falsy value, BigInt ... store large numbers that are not accommodated by the Number data type. ... The javascript falsy value, null is the representation of a variable with an empty value....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ what-are-falsey-values-in-javascript
What are Falsy Values in JavaScript? Explained with Examples
April 2, 2025 - Here are the six falsy values in JavaScript: false: The boolean value false. 0: The number zero. "" or '' or ````: An empty string. null: The null keyword, representing the absence of any object value.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ falsy-in-javascript
Falsy in JavaScript - GeeksforGeeks
July 23, 2025 - Although both are falsy, they are used differently. null often represents a absence of a value, while undefined usually indicates it is not yet initialize.
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ javascript โ€บ truthy and falsy values: when all is not equal in javascript
Truthy and Falsy Values: When All is Not Equal in JavaScript โ€” SitePoint
November 11, 2024 - If the first operand is falsy, JavaScript will return the second operand. Yes, in JavaScript, several non-Boolean values are considered falsy. These include the number 0, an empty string โ€œโ€, null, undefined, NaN, and -0.
Top answer
1 of 3
17

A common misconception

"...If double equalto (==) operator only checks/compares for values & not for types..."

That's an incorrect assumption, though it's often repeated by people. In reality, the == does check types, and in fact pays far more attention to the types than a === comparison does.

See Abstract Equality Comparison Algorithm.

A == comparison doesn't do a simple toBoolean conversion. Rather it walks through a somewhat complex recursive algorithm, which, after checking the types, attempts to coerce the operands to the same type if they don't match.

The type coercion that it performs is very specific to the types of the operands. A different sequence of coercions can take place for different type pairs. Usually (but not always) it ends up ultimately coercing the operands down to number types.


Why !ing the operands changes things

When you manually coerce both operands using !, you're now doing a simple toBoolean conversion causing the types to match, which avoids the type coercive part of the algorithm, making it behave essentially like the Strict Equality Comparison Algorithm.

So the only way to predict the outcome of a == comparison when the types don't match is to understand that Abstract algorithm.


Don't forget about NaN

And FYI, there's one more "falsey" value to consider, NaN. Its == comparison will always be false, no matter what. Even when comparing to another NaN value, it'll be false.

2 of 3
1

undefined: means a variable was declared but has no value assigned

null: the value of null has been assigned, which means it has no value

false, '' and 0 I think you can probably work out what these mean.

๐ŸŒ
HowDev
how.dev โ€บ answers โ€บ what-are-falsy-values-and-truthy-in-javascript
What are falsy values and truthy in JavaScript?
So, if you want to check whether a variable initialized with null has been initialized with a value, null will return false. ... The first part will log no, not yet while the second part will log yes, initialized. undefined is assigned to a ...
๐ŸŒ
Medium
medium.com โ€บ coding-at-dawn โ€บ what-are-falsy-values-in-javascript-ca0faa34feb4
What are falsy values in JavaScript? | by Dr. Derek Austin ๐Ÿฅณ | Coding at Dawn | Medium
March 1, 2023 - The falsy values in JavaScript are 0, 0n, null, undefined, false, NaN, and the empty string โ€œโ€. They evaluate to false when coerced byโ€ฆ
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-check-if-value-is-falsy
Check if a Value is Falsy or Truthy in JavaScript | bobbyhadz
The if statement checks if the value stored in the variable is truthy. Truthy are all values that are not falsy. The falsy values in JavaScript are: false, 0, "" (empty string), null, undefined, NaN (Not a number).