One dangerous issue of falsey values you have to be aware of is when checking the presence of a certain property.

Suppose you want to test for the availability of a new property; when this property can actually have a value of 0 or "", you can't simply check for its availability using

if (!someObject.someProperty)
    /* incorrectly assume that someProperty is unavailable */

In this case, you must check for it being really present or not:

if (typeof someObject.someProperty == "undefined")
    /* now it's really not available */

Also be aware that NaN isn't equal to anything, even not to itself (NaN != NaN).

Answer from Marcel Korpel on Stack Overflow
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ falsy-values-in-javascript
Falsy Values in JavaScript
December 14, 2019 - It is possible to check for a falsy value in a variable with a simple conditional: if (!variable) { // When the variable has a falsy value the condition is true.
Top answer
1 of 6
29

One dangerous issue of falsey values you have to be aware of is when checking the presence of a certain property.

Suppose you want to test for the availability of a new property; when this property can actually have a value of 0 or "", you can't simply check for its availability using

if (!someObject.someProperty)
    /* incorrectly assume that someProperty is unavailable */

In this case, you must check for it being really present or not:

if (typeof someObject.someProperty == "undefined")
    /* now it's really not available */

Also be aware that NaN isn't equal to anything, even not to itself (NaN != NaN).

2 of 6
8

There are two separate issues with 'falsey' values in JavaScript.

Firstly there is the official conversion scheme, which is what is returned by Boolean(x). This returns false when x is false or 0 or NaN or null or undefined or "" and true otherwise. This is the same behaviour as the

if (condition) {/*true path*/} else {/*false path*/}

that is, the false path is executed if Boolean(condition) would have returned false and the true path is executed otherwise. This behaviour is often used to check to see if a property is defined. However, doing that is not safe unless you are certain that the property would be an object or an array if it is defined. The safest way to test if a property is defined is to do

if (property != null) { /*property is defined*/} 

which makes sure that the property is not null or undefined. If you only want to make sure the property is not undefined do

if (property !== undefined) { /*property is not undefined (but may be null)*/ } 

(notice the extra = in !==).

Secondly, there are all the values that == false. This is everything that can be coerced to 0 (which is what false gets coerced to). This includes all the values that convert to false except NaN (which can't == false by virtue of it never == anything), null and undefined. But it also includes all objects that when converted to a string and then converted to a number are equal to 0. For example, this includes everything that when converted to a string is either the empty string "" or "0" or "-0" or "+0" or "0x00" or "000" or "0e0" or "0.0000"...., for example,

({toString: function() {return "-00.0e000";}}) == false

is true. Interestingly, this includes the empty array, and any nesting of arrays containing only a single other item that returns an empty or 0 string since arrays rendered as strings show only the contents without the surrounding brackets. That is,

[[[[0]]]] == false; // Because [[[[0]]]].toString() === "0"
[] == false;
[[[""]]] == false;
["0"] == false;
[[({toString: function() {return "0";}})]] == false;

The full algorithm for calculating == false is described here.

The reason this matters is because it can lead to subtle, difficult to find bugs if you don't understand most of these rules. Most important takeaways are probably how the if (condition) works and that using === avoids most of the other crazy stuff.

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Glossary โ€บ Falsy
Falsy - Glossary | MDN
A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context. JavaScript uses type conversion to coerce any value to a Boolean in contexts that require it, such as conditionals and loops.
๐ŸŒ
Medium
medium.com โ€บ front-end-weekly โ€บ how-to-identify-falsy-values-in-javascript-76aabe1c3f7a
How to Identify Falsy Values in JavaScript | by John Au-Yeung | Frontend Weekly | Medium
October 11, 2019 - negate it back to the actual boolean value. !!(false); // false !!(0); // false !!(""); // false !!(''); // false !!(``); // false !!(undefined); // false !!(null); // false !!(NaN); // false ... const abc = false && "abc"; // false, since false is false and "abc" is trueconst def = false || "def"; // true, since false is false and "def" is true ยท It is always good to check for falsy values like null and undefined to avoid crashes.
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 25-js-essentials-falsy-values
JS Essentials: Falsy Values | SamanthaMing.com
Here are some sample values that you might have thought was true (at least I did), but it actually evaluates to true. Remember if it's not on the false list, it's true!
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ what-are-falsey-values-in-javascript
What are Falsy Values in JavaScript? Explained with Examples
April 2, 2025 - Here, we are checking the boolean value of all six falsy values. And as expected, each returns false. When you pass any other value that's not one of these six falsy values to the Boolean function, it will return true. ... Example boolean log results for truthy values. There are some truthy values that, at a glance, may appear to be falsy values but aren't. As already mentioned, only six values in JavaScript are falsy values.
Find elsewhere
๐ŸŒ
Zipy
zipy.ai โ€บ blog โ€บ truthy-and-falsy-values-in-javascript
truthy and falsy values in javascript
April 12, 2024 - Be Explicit: When the distinction between different falsy values matters, use explicit checks (e.g., typeof variable !== 'undefined' or variable !== null) to avoid confusion and bugs.
๐ŸŒ
Adripofjavascript
adripofjavascript.com โ€บ blog โ€บ drips โ€บ truthy-and-falsy-values-in-javascript.html
Truthy and Falsy Values in JavaScript - A Drip of JavaScript
We don't need to explicitly check for undefined, "", etc. Instead we can just check whether person.skepticism is truthy. However, there some caveats to keep in mind. Firstly, this approach only works if all of the falsy values should be excluded (or included.)
๐ŸŒ
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 - To avoid errors when working with truthy and falsy values, avoid direct comparisons, use strict equality comparisons, and convert to real Boolean values when necessary. This can help ensure that a false is generated only by false, 0, โ€œโ€, null, undefined, and NaN, preventing unexpected behavior. JavaScript variables are loosely/dynamically typed and the language doesnโ€™t care how a value is declared or changed:
๐ŸŒ
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 field does not exist (making it undefined). We can fix our code by explicitly checking that user.loyaltyPoints does not equal undefined instead of evaluating the valueโ€™s truthiness.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what values does javascript consider falsy?
What Values Does JavaScript Consider Falsy? - Scaler Topics
December 20, 2022 - The variables can be checked for falsy values under if...else statements to control the flow of the program. ... Let us see how the variables are loosely compared using the == operator.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ falsy-in-javascript
Falsy in JavaScript - GeeksforGeeks
July 23, 2025 - Understanding falsy values can help avoid common pitfalls in JavaScript ยท You can use || to provide a default value if the left operand is falsy. ... Falsy values cause logical operations to short-circuit.
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ falsy
What is "Falsy" in JavaScript? - Mastering JS
Checking if v == null is equivalent to v === null || v === undefined. In other words, a value is loosely equal to null only if it is strictly equal to null or undefined. So checking if v == null is often more accurate than checking for truthy or falsy values.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Glossary โ€บ Truthy
Truthy - Glossary | MDN
Examples of truthy values in JavaScript (which will be coerced to true in boolean contexts, and thus execute the if block): ... if (true); if ({}); if ([]); if (42); if ("0"); if ("false"); if (new Date()); if (-42); if (12n); if (3.14); if (-3.14); if (Infinity); if (-Infinity);
๐ŸŒ
Shameem
shameem.me โ€บ home โ€บ mastering the concept of truthy and falsy values in javascript
Mastering the Concept of Truthy and Falsy Values in JavaScript - Shameem
January 26, 2023 - Therefore, the entire expression will be evaluated to โ€œhelloโ€ and returned. In JavaScript, you can check if a value is truthy or falsy by using the if statement or the Boolean() function.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ introduction-to-javascript-for-front-end-engineers โ€บ lessons โ€บ decoding-javascript-truthy-and-falsy-values-conditional-statements-logical-operators-and-equality-operations
Decoding JavaScript: Truthy and Falsy Values, Conditional ...
For example, you want to check if the bakery is closed is the same as checking if the bakery is not open: Here, if bakeryOpen is false, !bakeryOpen becomes true, and it will print the message indicating that the bakery is closed. ... Congratulations! In this lesson, we have familiarized ourselves with truthy and falsy values, conditional statements, logical operators, and equality operations.
๐ŸŒ
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 - Always check type + content for strings and arrays (typeof x === "string" && x.trim() !== ""). Use Array.isArray() instead of instanceof Array for reliability. For objects, combine truthiness and Object.keys(obj).length to ensure they are not empty. Dealing with null, undefined, empty strings, or falsy values is part of everyday JavaScript coding.