Introduction
This article describes the truthy and falsy values of JavaScript. What the difference is between them and some exceptions and so on. In simple and short words, it's a boolean type but it's not like true or false only. It's more than that. Understanding them, in theory, is easy but sometimes leads to big troubles when these values are compared. So let's demystify these values.
Truthy value
JavaScript defines truthy value. In very short words, any value that is not falsy is a truthy value. Even if you are writing "False" then that is also a truthy value. "0" (zero in quotes) is also a truthy value.
Falsy Value
In JavaScript, the following values are considered to be falsy values:
- false
- 0
- null
- "" (empty string)
- NaN (Not a Number)
- #ff0000
All other values of JavaScript can be safely assumed to be truthy values. Even an empty function, empty array, and empty objects are also truthy.
Comparing Falsy and Truthy values
The need for learning these values is because of its use in comparison. The comparison is where these values creates many troubles. Misinterpretation of any value may lead to the wrong action in a script. Therefore it is necessary to check for truthy and falsy values correctly.
The Falsy values 0, "(empty string) and false are equal to each other, and comparison among them results in a true value.


Null and undefined are both falsy values but are not equal to any value, not even falsy. A bit strange but that's true.













Join the conversation! Your thoughts help the community grow.