Search code examples
javascriptzerofalsy

Operator to test for falsy values with zero treated as truthy


Is there a minimalistic syntax to do the same as x === 0 ? true : !!x. The goal of this expression is to avoid the exclusion of zero as falsy and yet make sure other falsy values do are converted to false.


Solution

  • Basically, you want to allow any number?

    typeof x === 'number'