Does javascript treat empty string as either a falsy or null value, and if so why?

Yes it does, and because the spec says so (§9.2).

Isn't an empty string still an object

No. An primitive string value is no object, only a new String("") would be (and would be truthy)

Answer from Bergi on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org › news › falsy-values-in-javascript
Falsy Values in JavaScript
December 14, 2019 - There are only six falsey values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false of course. It is possible to check for a falsy value in a variable with a simple conditional: if (!variable) { // When the variable has a falsy ...
🌐
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”.
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 › truthy-in-javascript
Truthy In JavaScript - GeeksforGeeks
July 23, 2025 - If you’ve ever wondered what JavaScript considers “true,” here’s the simple answer: any value that is not explicitly falsy (like false, 0, null, undefined, NaN, or an empty string "") is considered truthy.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Falsy
Falsy - Glossary | MDN
Examples of falsy values in JavaScript (which are coerced to false in Boolean contexts, and thus bypass the if block):
Find elsewhere
🌐
Medium
medium.com › @python-javascript-php-html-css › validating-empty-undefined-or-null-strings-in-javascript-fe483c3340ad
JavaScript Validation of Null, Undefined, and Empty Strings
August 24, 2024 - A string in JavaScript is considered truthy unless it is empty (‘’), null, or undefined, which are all falsy values. This behavior underpins many of the shorthand techniques used for validation but also requires a clear understanding to avoid unintended consequences.
🌐
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 - For example, the number 0 is falsy, but the string “0” is truthy. This is because an empty string is falsy, but a non-empty string, even if it contains a character that represents a falsy value, is truthy.
🌐
Trevor Lasn
trevorlasn.com › home › blog › javascript truthy and falsy values: complete reference
JavaScript Truthy and Falsy Values: Complete Reference
November 1, 2024 - The empty array comparison [] == false evaluates to true, yet an empty array is actually truthy. This happens because JavaScript first converts the array to a primitive value. When an empty array is converted to a primitive, it becomes an empty ...
🌐
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?
March 31, 2022 - In the first statement, a is getting a number 0 and number 0 is a falsy value and any number above or below 0 ia truthy, so it correctly showed 0 as false. In the second statement, a is getting 0 as a string and only empty string ' ' is falsy and anything inside string is truthy value, so it correctly displayed true.
🌐
GitBook
basarat.gitbook.io › typescript › recap › truthy
Truthy | TypeScript Deep Dive
The following things are truthy in JavaScript. An example is any number other than 0 e.g. Copy · if (123) { // Will be treated like `true` console.log('Any number other than 0 is truthy'); } Something that isn't truthy is called falsy. Here's a handy table for your reference. Variable Type · When it is falsy · When it is truthy · boolean · false · true · string · '' (empty string) any other string ·
🌐
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.
🌐
LinkedIn
linkedin.com › pulse › mastering-truthy-falsy-values-javascript-key-efficient-mohammed-osman
Mastering Truthy and Falsy Values in JavaScript: A Key to Efficient Coding and Avoiding Pitfalls
May 28, 2023 - This is because 0 is a falsy value in JavaScript. Another common pitfall is the misunderstanding of truthy and falsy values when dealing with logical operations. For instance: let str = "" if (str && str.length) { console.log("This code will ...
🌐
Zipy
zipy.ai › blog › truthy-and-falsy-values-in-javascript
truthy and falsy values in javascript
April 12, 2024 - Any value in JavaScript that is not on the falsy list is considered truthy. This includes: All strings except the empty string ("hello", '123', etc.).
🌐
Sentry
sentry.io › sentry answers › javascript › how do i check for an empty/undefined/null string in javascript?
How do I Check for an Empty/Undefined/Null String in JavaScript? | Sentry
This logical && operator expression returns true if a string is empty or consists of white space and line terminator strings only. YoutubeHow Sentry.io saved me from disaster (opens in a new tab) ResourcesImprove Web Browser Performance - Find ...
🌐
Medium
medium.com › @OdeyComfort2 › falsy-and-truthy-values-in-javascript-9d55323564a5
Falsy and Truthy Values in JavaScript | by Comfort Odey | Medium
January 24, 2024 - The example above evaluates to true even when one of the value is wrapped in string. Other truthy values includes empty string with space in it(“ “) functions with nothing in it (const var1 = function() {};.
🌐
sqlpey
sqlpey.com › javascript › javascript-check-empty-falsy
JavaScript: How to Check for Empty Strings and Falsy Values? …
July 25, 2025 - This includes non-empty strings, numbers other than zero, objects, and arrays. // Example of a truthy check let myData = "some value"; if (myData) { console.log("myData has a truthy value."); // This will log } let zeroValue = 0; if (zeroValue) { console.log("zeroValue is truthy."); // This will not log }