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 › 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....
🌐
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 ...
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

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)
🌐
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
Top answer
1 of 4
44

Is this the expected behavior.

Yes.

If so then why ?Am I missing some concept/theory about undefined in Javascript?

JavaScript has the concept of implicit conversion of values (aka coercing values). When you use the negation ("NOT") operator (!), the thing you're negating has to be a boolean, so it converts its argument to boolean if it's not boolean already. The rules for doing that are defined by the specification: Basically, if the value is undefined, null, "", 0, 0n, or NaN (also document.all on browsers¹), it coerces to false; otherwise, it coerces to true.

So !undefined is true because undefined implicitly converts to false, and then ! negates it.

Collectively, those values (and false) are called falsy values. Anything else¹ is called a truthy value. This concept comes into play a lot, not just with !, but with tests in ifs and loops and the handling of the return value of callbacks for certain built-in functions like Array.prototype.filter, etc.


¹ document.all on browsers is falsy, even though it's an object, and all (other) objects are truthy. If you're interested in the...interesting...history around that, check out Chapter 17 of my recent book JavaScript: The New Toys. Basically, it's to avoid sites unnecessarily using non-standard, out of date features.

2 of 4
3

Yes, it is the expected behavior.

Negation of the following values gives true in javaScript:

  • false
  • undefined
  • null
  • 0 (number zero)
  • ""(empty string)

eg: !undefined = true

Note: The following checks return true when you == compare it with false, but their negations will return false.

  • " "(space only).
  • ,

eg: [ ] == false gives true, but ![ ] gives false

🌐
Educative
educative.io › answers › what-are-falsy-values-and-truthy-in-javascript
What are falsy values and truthy in JavaScript?
In JavaScript, we have 6 falsy values: false · 0 (zero) ‘’ or “” (empty string) null · undefined · NaN · All these return false when they are evaluated. If we write the following: // bool.js · if(false) { console.log("yes") } Run ...
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › javascript › truthy and falsy values in javascript
Truthy and falsy values in JavaScript | Sentry
Because 0 is a falsy value, the if condition in our displayLoyaltyPoints() function will evaluate to false when provided with a user whose loyaltyPoints property is set to 0. The if condition will also evaluate to false if the loyaltyPoints ...
🌐
DEV Community
dev.to › anthonybanion › checking-null-undefined-empty-and-falsy-values-in-javascript-2io5
Checking `null`, `undefined`, Empty, and Falsy Values in JavaScript - DEV Community
August 17, 2025 - In JavaScript, values are evaluated in Boolean contexts as either truthy or falsy. ... Everything else is considered truthy (including "0", "false", [], {}, etc.). ... if (!0) console.log("0 is falsy"); // ✅ if (!"") console.log("Empty string"); ...
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › differences between falsy and nullish values in js
Differences Between Falsy and Nullish Values in JavaScript
July 8, 2025 - In contrast to falsy values, nullish values are only considered false in a Boolean context when they are null or undefined. Any other falsy value, like 0, false, or '', is not considered nullish.
🌐
J11y
j11y.io › javascript › truthy-falsey
Truthy & Falsey – James Padolsey
An object of any kind (including functions, arrays, RegExp objects, etc.) is always truthy. The easiest way to determine if something is truthy is to determine that it’s not falsey. There are only six falsey values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false, of course.
🌐
SamanthaMing
samanthaming.com › tidbits › 25-js-essentials-falsy-values
JS Essentials: Falsy Values | SamanthaMing.com
// JS Essentials: Falsy Values false undefined null NaN 0 or +0 or -0 "" or '' or `` (empty string) // Everything else is truthy
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Truthy
Truthy - Glossary | MDN
In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy. That is, all values are truthy except false, 0, -0, 0n, "", null, undefined, NaN, and document.all.
🌐
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…
🌐
Scaler
scaler.com › home › topics › what values does javascript consider falsy?
What Values Does JavaScript Consider Falsy? - Scaler Topics
December 20, 2022 - There are 6 falsy values in javascript and are used in if cases to control the flow of the program. These falsy values can be evaluated using loose and strict equality. All objects are not falsy objects as even empty objects are not undefined.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › falsy
What is "Falsy" in JavaScript? - Mastering JS
In JavaScript, a value is falsy if JavaScript's built-in type coercion converts it to false.
🌐
Nfriedly
nfriedly.com › techblog › 2009 › 07 › advanced-javascript-operators-and-truthy-falsy
Advanced Javascript: Logical Operators and truthy / falsy
When javascript is expecting a boolean and it’s given something else, it decides whether the something else is “truthy” or “falsy”. An empty string (''), the number 0, null, NaN, a boolean false, and undefined variables are all “falsy”. Everything else is “truthy”.
🌐
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).