It means that undefined is a falsy value, list of falsy values are:

""        // Empty string
null      // null
undefined // undefined, which you get when doing: var a;
false     // Boolean false
0         // Number 0
NaN       // Not A Number eg: "a" * 2

If you negate a falsy value you will get true:

!""        === true
!null      === true
!undefined === true
!0         === true
!NaN       === true

And when you nagate a truthy value you will get false:

!"hello" === false
!1       === false

But undefined is not equal false:

undefined === false // false
undefined  == false // false

And just for the fun if it:

undefined == null // true
Answer from Andreas Louv on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › undefined
undefined - JavaScript | MDN
You can use undefined and the strict equality and inequality operators to determine whether a variable has a value. In the following code, the variable x is not initialized, and the if statement evaluates to true.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Falsy
Falsy - Glossary | MDN
A falsy (sometimes written falsey) ... conditionals and loops. The following table provides a complete list of JavaScript falsy values: The values null and undefined are also nullish....
🌐
Webmaster World
webmasterworld.com › javascript › 5090854.htm
Easy way to convert undefined to false? - JavaScript and AJAX forum at WebmasterWorld - WebmasterWorld
var[counter] ?= false; My goal here is to minimize the code to shave off a few microseconds :-) ... My intuition says if you don't know the inputs then it's undefined behaviour. That said, typeof x === 'undefined' So (y = typeof(x === 'undefined' ?
🌐
freeCodeCamp
freecodecamp.org › news › javascript-check-if-undefined-how-to-test-for-undefined-in-js
JavaScript Check if Undefined – How to Test for Undefined in JS
November 7, 2024 - An undefined variable or anything without a value will always return "undefined" in JavaScript. This is not the same as null, despite the fact that both imply an empty state. You'll typically assign a value to a variable after you declare it, ...
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)
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
In the strictest sense, null represents ... operator coerces operands of different types to boolean values, making null and undefined both false....
Find elsewhere
🌐
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 ...
🌐
CodeBurst
codeburst.io › understanding-null-undefined-and-nan-b603cb74b44c
Understanding null, undefined and NaN. | by Kuba Michalski | codeburst
November 12, 2018 - Negating null value returns true , but comparing it to false (or either true) gives false. In basic maths operations, null value is converted to 0. The global undefined property represents the primitive value undefined.
🌐
Greenroots
blog.greenroots.info › javascript-undefined-and-null-lets-talk-about-it-one-last-time
JavaScript undefined and null: Let's talk about it one last time!
November 6, 2020 - undefined and null are primitive values and they represent falsy values. All the similarities between undefined and null end here. undefined value is typically set by the JavaScript engine when a variable is declared but not assigned with any ...
🌐
Quora
quora.com › What-is-the-difference-between-undefined-null-and-false
What is the difference between 'undefined', 'null', and 'false'? - Quora
Answer: In most programming languages there is undefined, null, and false is a value given to a Boolean variable. When it comes to any variable null means that it wasn’t assigned any value.
🌐
Quora
quora.com › Why-is-null-undefined-true-in-JavaScript
Why is (null==undefined) true in JavaScript? - Quora
Answer (1 of 7): Actually, there is no satisfactory reason for that. I am too confused with this. Some say both are actually falsy values, so it evaluates to true, but i don’t get this logic. I mean i want to know what thing is being converted to what if type coercion is happening.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-determine-if-variable-is-undefined-or-null-in-javascript.php
How to Determine If Variable is Undefined or NULL in JavaScript
<script> var firstName; var lastName ... // Print: true console.log(null === undefined) // Print: false /* Since null == undefined is true, the following statements will catch both null and undefined */ if(first...
🌐
Quora
quora.com › Why-does-JavaScript-return-true-when-a-variable-is-not-defined
Why does JavaScript return true when a variable is not defined? - Quora
Answer (1 of 2): It doesn’t, or at least shouldn’t, since undefined is one of the falsy values. https://www.30secondsofcode.org/js/s/truthy-falsy-values/
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › falsy-in-javascript
Falsy in JavaScript - GeeksforGeeks
July 23, 2025 - false is falsy. 0 is falsy. 0 is falsy. 0 is falsy. is falsy. null is falsy. undefined is falsy. NaN is falsy. Understanding falsy values can help avoid common pitfalls in JavaScript
🌐
Bennadel
bennadel.com › blog › 4783-comparing-undefined-values-with-optional-chaining-in-javascript.htm
Comparing Undefined Values With Optional Chaining In JavaScript
April 17, 2025 - But, as we've demonstrated above, the undefined value always results in false when compared to numbers. Which means this: ... This JavaScript behavior can simplify our if blocks when it comes to things lie the indexOf() comparison.
🌐
Quora
quora.com › How-do-you-avoid-getting-an-undefined-result-if-only-expecting-true-or-false-in-JavaScript
How to avoid getting an undefined result if only expecting true or false in JavaScript - Quora
Answer (1 of 4): If you expect “isSameLanguage” to return a boolean, you’re going to be disappointed. forEach is going to run an blocking loop and the return closure is going to close out the callback function of that loop and not close “isSameLanguage”. To have this perform the way you intend, u...
🌐
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…