DEV Community

Discussion on: True Is Not Always True In JavaScript

Collapse
 
mdor profile image
Marco Antonio Dominguez

I disagree with this.

The falsy values are just:

  • undefined
  • null
  • 0 (-0, 0, +0)
  • NaN
  • empty strings ("", '', ``)
  • false

The document.all is an exception and I won't even use this in a codebase. If you try the typeof operator returns an "undefined", that's the reason no the function itself. Also, this is used by older browsers and is equivalent to document.getElementById.

In addition, "always better to handle pure boolean values." shows the lack of understanding about JS. falsy objects are helpful and the ability to coerce types makes it easier to work with them, with and without TS.