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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Falsy
Falsy - Glossary | MDN
July 11, 2025 - 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 }
Discussions

Falsy values vs null, undefined, or empty string
I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
Javascript empty string is not empty
Maybe its not an empty string, and instead a string of one or more invisible characters. const id = '­' // or '\u00AD' if stripped by reddit console.log(id) // '' console.log(id.trim().length) // 1 More on reddit.com
🌐 r/learnjavascript
12
3
March 2, 2022
What are falsy values in JS? What are truthy values in JS?
What are truthy values in JS? Answer A falsy value is one that evaluates to the boolean value false - expressions, statements, and values can evaluate to the false boolean value and will therefore be considered a falsy value. Some falsy values to remember: false 0 (or other forms of the number 0, -0, 0.0, etc) empty strings ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
3
August 20, 2018
Why 0 doesn't get the falsey if condition.
Hi there, Ricardo Osorio! You're correct that 0 is considered falsy. However, any input that is read in through the prompt is a string. Any non-empty string is considered truthy. More on teamtreehouse.com
🌐 teamtreehouse.com
1
February 10, 2022
🌐
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”.
🌐
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 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)
🌐
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 - An empty array is truthy — yet comparing with true is false and comparing with false is true?!. Note the difference in how empty values across various types can be evaluated. An empty string or undefined value are falsy, but an empty array ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnjavascript › javascript empty string is not empty
r/learnjavascript on Reddit: Javascript empty string is not empty
March 2, 2022 -

They closed my question on SO because it's not reproducible, but that's exactly why I posted, because code isn't behaving as it should.

Anyway, I 'm receiving a JSON result from a web service. It looks something like this:

{ "data": [{ "id": "123ABC", "name" : "Test 1" }, { "id": "", "name" : "Test 2" }] }

I 'm looping through the data array and need to determine if an id exists or not:

for( const item of data ) {
    if( item.id !== null && item.id.trim().length > 0 ) {
        doSomething();
    } else {
        doSomethingElse();
    }
}

My problem is that doSomething() fires for the first item ("123ABC") but also fires for the second where the id is empty.

I've tried spitting out the values for the second item:

console.log("NULL ", item.id === null);
console.log("EMPTY ", item.id.trim().length === 0);

and results are

NULL  false
EMPTY  false

so I'm wondering if there's something strange about the id value.

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › falsy-in-javascript
Falsy in JavaScript - GeeksforGeeks
July 23, 2025 - The BigInt value 0n is falsy. ... Strings without any characters (empty strings) are falsy, but strings with whitespace or content are truthy.
🌐
Medium
medium.com › the-amateur-dev › truthy-and-falsy-javascripts-weird-idea-of-true-and-false-1d1c0410ad4c
Truthy and Falsy: JavaScript’s Weird Idea of True and False | by Uloaku Obi | The Amateur Dev | Jan, 2026 | Medium
January 17, 2026 - Another place this shows up is ... returns the first truthy value it finds. And since an empty string is falsy, it skips to the default....
🌐
Luis Llamas
luisllamas.es › inicio › cursos › curso javascript
Falsy and Truthy Values in TypeScript
December 6, 2024 - if ("hello") { console.log("A non-empty string is truthy"); } if ({}) { console.log("An empty object is truthy"); } ... In JavaScript (and in other languages to a lesser extent), some programmers have the habit of relying on the implicit evaluation of these properties to “simplify” the code. This way they save themselves from explicitly comparing with true or false (maybe they get charged per letter or something)
🌐
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 ...
🌐
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.
🌐
Medium
medium.com › @nehatanwar.dev › understanding-truthy-and-falsy-values-in-javascript-b1e18f01f3b5
Understanding Truthy and Falsy Values in JavaScript | by Nehatanwar | Medium
January 11, 2025 - Knowing how truthy and falsy values work helps in writing more efficient and readable code. Instead of explicitly comparing variables to true or false, you can rely on JavaScript’s automatic type conversion. For example, you can test if a string is non-empty or a number is non-zero without ...
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › javascript faq
What are falsy values in JS? What are truthy values in JS?
August 20, 2018 - Answer A falsy value is one that ... be considered a falsy value. Some falsy values to remember: false 0 (or other forms of the number 0, -0, 0.0, etc) empty strings ......
🌐
Scaler
scaler.com › home › topics › what values does javascript consider falsy?
What Values Does JavaScript Consider Falsy? - Scaler Topics
December 20, 2022 - The value false is converted to 0. By the rule, if the value is to be compared in our object and number, then the object is converted to primitive form. The empty array([]) is converted to an empty string('').
🌐
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 - A truthy value is one that is considered true when evaluated in this context. Conversely, a falsy value is considered false. JavaScript defines six falsy values: false, 0, '' (empty string), null, undefined, and NaN.