Hello Everyone,
In this post we will explore the truthy and falsy values in JavaScript. This is going to be a very short to the point blog post. So, let’s get started.
Truthy and Falsy Values
- Any value that evaluates to true in Boolean Context is truthy value.
For instance
1console.log(Boolean("Hello World!"));2// true
- Any value that evaluates to false in Boolean Context is falsy value.
For instance
1console.log(Boolean(0));2// false
The only 6 falsy values
There are only 6 falsy values. Everything else (other than these 6 values) evaluates to true in boolean context.
1- ""2- 03- false
The above 3 values are equal to each other.
1- undefined2- null
The above 2 values loosely equalls (==) to each other and nothing else.
1- Nan
NaN is the only value that is not even equal to itself.
1console.log(NaN == NaN);2// false
So, that’s it for this post, I will see you in some other post. If you found this one helpful, do share it and join my newsletter below or here.
Thank You!