What are Truthy and Falsy Values in JavaScript?
Introduction
I wanted to write a blog post about understanding type coercion and in the process of starting to write that post, the concept of truthy and falsy values continually came up. I decided that I should probably discuss truthy and falsy values first.
What Are Truthy and Falsy Values?
Truthy values are expressions that evaluate to the boolean value of true, and falsy values are expressions that evaluate to the boolean value of false. I have included a table with expressions that are falsy.
Anything other than these six expressions is considered a truthy value. To see this in action, let’s look at the code example below.
Code
In the code example above, the expression is true because both 0
and “”
(empty string) are both falsy values. So when we compare them against each…