This is because the Abstract Equality Comparison Algorithm requires that if Type(x) or Type(y) is a Boolean in the expression x == y then the Boolean value should be coerced to a number via ToNumber, which converts true to 1 and false to +0.

This means that any comparison of true == something or something == true results in 1 == something or something == 1 (replacing true and 1 with false and +0 for false).

The Null type does not compare as equal to either 1 or +0 (in fact, null is only comparable to undefined in the Abstract Equality Comparison Algorithm).

There is a detailed discussion of all of the different kinds of equality in JavaScript on MDN that is well worth looking at if you want to know more.

However, if you coerce null to a number it is coerced to +0 so +null == false actually returns true.

Answer from Sean Vieira on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
When checking for null or undefined, beware of the differences between equality (==) and identity (===) operators, as the former performs type-conversion. ... typeof null; // "object" (not "null" for legacy reasons) typeof undefined; // "undefined" null === undefined; // false null == undefined; // true null === null; // true null == null; // true !null; // true Number.isNaN(1 + null); // false Number.isNaN(1 + undefined); // true
People also ask

What is a null check?
In JavaScript, null represents an intentional absence of a value, indicating that a variable has been declared with a null value on purpose. On the other hand, undefined represents the absence of any object value that is unintentional. A null check determines whether a variable has a null value, meaning a valid instance of a type exists.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
What is a strict null check?
StrictNullChecks is a feature that treats null and undefined as two separate types, reducing errors and making it easier to find coding bugs. It also has stronger measures for defining variables as null or undefined, ensuring variables are declared as null only when it’s safe to do so.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
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)
🌐
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.
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
null == undefined > true null === undefined > false · Unlike the reserved keyword null, undefined is a property of the global object. This was a design decision made early in JavaScript's development, and it let legacy browsers overwrite undefined completely.
🌐
Pranay Goel's Blog
pranaygoel.hashnode.dev › demystifying-null
Demystifying null in Javascript. Why is null >= 0 equal to true?
August 14, 2023 - Hence, the expression is evaluated as true. ... Here, null is converted to undefined, which is then converted to NaN, which of course isn't 0. Hence, the expression is evaluated as false.
Find elsewhere
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
Null is not considered false in JavaScript, but it is considered falsy. This means that null is treated as if it’s false when viewed through boolean logic. However, this is not the same thing as saying null is false or untrue.
Published   August 4, 2025
🌐
freeCodeCamp
freecodecamp.org › news › javascript-nullable-how-to-check-for-null-in-js
JavaScript Nullable – How to Check for Null in JS
July 7, 2022 - JavaScript uses coercion to coerce values from one type to another in order to be able to use them in a Boolean context. But by strictly checking for equality, you can see that they are in fact not equal. The best way to check for null is to use strict and explicit equality: console.log(leviticus === null) // true console.log(dune === null) // false
🌐
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 12, 2020 - A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context. In JavaScript, there are 6 falsy values including undefined and null, ... Apart from the similarities mentioned above, undefined and null are way apart from each other. They are strictly not equal, (undefined === null) // returns, false (undefined !== null) // returns true...
🌐
SitePoint
sitepoint.com › javascript
Could someone explain why "" != null? - JavaScript - SitePoint Forums | Web Development & Design Community
October 14, 2016 - You are basically assigned the string to variable, even if it’s empty - so that’s empty string, and for sure it would return it as false. ... The difference comes on how its handled in memory by the interpreter. So when creating a variable what you are really doing is assigning a memory address for the variable. And when you assign a value to that variable you are effectively creating another memory address for that value. But when you do not add a value or the value is NULL the memory address for the value is never created.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-if-a-variable-is-not-null-in-javascript
How to check if a Variable Is Not Null in JavaScript ? - GeeksforGeeks
August 5, 2025 - It is not null · In this approach, ... the _.isNull() method which returns true or false according to the given value. If the value is not null then it will return false. It will return the true if the given value is null...
🌐
Flexiple
flexiple.com › javascript › undefined-vs-null-javascript
Undefined vs Null - Javascript - Flexiple
As promised, now let’s look as to why the type of null is an “object”. As it then indicates that null must be an object, which is not true. In fact, null is one of the primitive values in JavaScript.
🌐
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. And undefined it means that the variable wasn’t even declared(for example trying to print a variable ...
🌐
Educative
educative.io › answers › what-are-falsy-values-and-truthy-in-javascript
What are falsy values and truthy in JavaScript?
null is evaluated to be false. null is used when we don’t want to assign a value yet to a variable. Mind you, the type of on null returns an object. So, if you want to check whether a variable initialized with null has been initialized with ...
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-null
Everything about null in JavaScript
The good way to check for null ... the expression existingObject === null evaluates to false. null, alongside false, 0, '', undefined, NaN, is a falsy value....
🌐
freeCodeCamp
freecodecamp.org › news › how-to-check-for-null-in-javascript
JS Check for Null – Null Checking in JavaScript Explained
November 7, 2024 - You can either use the loose/double equality operator (==) or the strict/triple equality operator (===). You can use the loose equality operator to check for null values: let firstName = null; console.log(firstName == null); // true · But, this can be tricky because if the variable is undefined, it will also return true because both null and undefined are loosely equal.
🌐
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 ...