loading...

There are 9 falsy values in JavaScript inside of a browser. Can you name them all?

Kenneth Lum on March 21, 2020

Sometimes when programming in JavaScript, it is easy to get an uncertain feeling of, what in JavaScript are falsy? It is slightly different if it ... [Read Full]
markdown guide
 

Is document.all really part of JS? I don’t think you can access it in node for example. So I would think it’s exposed via the browser api, and behavior on the browser itself.

But really great write up, thank you!

 

I guess just a familiar JS environment (some of us grew up with)... I think the amazing thing is, if the browser complies to JS, there is no way that it can make document.all to be falsy? If there are some weird things happening in NodeJS regarding JS I'd hope to know too.

By the way... I updated the post to mention it is inside of a browser, thank you.

 

Good write-up!

One note though... Actually, technically speaking, and according to the JavaScript specs (ECMA 262), there are only 7 values that are Falsy, meaning that they are considered false when encountered in a Boolean context.
And when it comes to document.all it's not part of the JavaScript specs per se. It's part of the DOM API (W3C), which browser-based only (Node.js doesn't have a document object, nor a DOM).

Cheers ;)

It is 7 but not 8? Which one is not listed... (I tried to search for "falsy" or "falsey" in that docs but can't find any match)... true, document.all really is inside of a browser only, so I think I will update the post

oh... not counting -0... depending on how you look at it. It can be incorrect, because 0 and -0 are technically different.

 

What about [], "\t" and "\r", I think those values are falsey too!

 

In Google Chrome or in NodeJS:

> !![]
true

> !!"\r"
true

> !!"\t"
true

> !!"\n"
true

> Boolean([])
true

!![] is the same as Boolean([])

In AngularJS some time ago, I remember AngularJS would consider [] to be falsy but in a later version to be truthy: stackoverflow.com/questions/357763...

 
code of conduct - report abuse