Swastik Yadav

S Y

Navigate back to the homepage

Truthy and Falsy values in JavaScript

Swastik Yadav
June 11th, 2021 · 1 min read

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- 0
3- false

The above 3 values are equal to each other.

1- undefined
2- 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!

More articles from Swastik Yadav

JavaScript Loose Equality vs Strict Equality check

What is the difference b/w loose equality (==) and strict equality (===) check in JavaScript.

June 4th, 2021 · 1 min read

Toggle functionality with pure CSS and no JavaScript

Create a compelete menu / sidebar toggle functionality with pure CSS and no JavaScript

May 31st, 2021 · 1 min read

DiaryOfADev, Success stories of underdog developers.

Every week we share an underdog developer's story and a deep dive into a programming concept.

© 2021–2024 Swastik Yadav
Link to $https://github.com/SwastikyadavLink to $https://www.linkedin.com/in/swastikyadav/