Haven't heard about truthy and falsy values in JavaScript?? This article will explain to you the truthy and falsy concepts in the easiest way possible.
Before diving into truthy and falsy values, let us understand what boolean data type is in JavaScript?
A JavaScript Boolean denotes one of two values: true or false. For example,
Boolean() function can be used to find out if an expression (or a variable) is true or false.
Now let us know about truthy and falsy values.
Falsy Values
- Falsy values are the values that are not actually false but will produce the result as false when converted into boolean.
- There are total 5 falsy values -
0, undefined, NaN, null, ''
.
Truthy Values
- Truthy values are the values that are considered true when converted into Boolean.
- All values except
false, 0, undefined, NaN, null, ''
are truthy values.
I hope you find this article simple and easy to understand JavaScript truthy and falsy values.