Swastik Yadav

S Y

Navigate back to the homepage
Subscribe

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

Become a better full-stack developer in 10 minutes a week.

Be the first to receive our latest content with the ability to opt-out at anytime. We promise to not spam your inbox or share your email with any third parties.



By subscribing, you agree with Revue’s Terms and Privacy Policy.
© 2021 Swastik Yadav
Link to $https://twitter.com/swastikJsDevLink to $https://github.com/SwastikyadavLink to $https://www.linkedin.com/in/swastik-yadav-6386b71b5/Link to $https://www.youtube.com/channel/UCHs73qDeimVFGTa-MzjtnLA