The 6 falsy values in Javascript
I'm a software developer in the Los Angeles area. I build web and fullstack applications, as well as participate in cybersecurity games (HTB, Vulnhub, OTW, etc).
Search for a command to run...
I'm a software developer in the Los Angeles area. I build web and fullstack applications, as well as participate in cybersecurity games (HTB, Vulnhub, OTW, etc).
No comments yet. Be the first to comment.
How long does it take to send a message through an entire organization.

Want to learn how to solve Leetcode problem 10: Regular Expression Matching, using GoLang? Then follow along as I explain how to implement regex matching in Golang. What is Dynamic Programming (DP)? Dynamic programming is a problem-solving approach u...

How long does it take to send a message through an entire organization.

Finding the maximum path sum in a Binary Tree.

How to Serialize and Deserialize a Binary Search Tree

If not, lets get into it, and learn a little bit about the double bang operator(!!) too !
When it comes to conditionals, javascript will use something call type coercion, or the implicit conversion of values from one data type to another, to evaluate whatever is in the conditional to either be either truthy (evaluates to true) or falsy (evaluates to false).
So without further ado, the 6 types considered falsy are:
false keywordundefined primitive valuenull primitive value'',"")NaN global property0, like 0.0,-0, or 0nSo what's truthy? Well thats simple, if it's not on the list above, its truthy! In other words, as long as it's not falsy, it's truthy.
For example, although an empty array([]) or likewise an empty object ({}) may at first seem to be false, since they are not on the list above, it is a fact that they are instead truthy!
A way I like to check the truthiness of a value is with the double-bang operator !! (or double-negation operator works too)
You can test this out in your browsers console:

Well that's it. I hope this little lesson on js booleans helped some people out.
You can read more about me or my current projects on my website