Search code examples
javascriptzero

Is minus zero a falsy value?


I have not found yet any discussion or article about falsy values in Javascript where minus zero is mentioned while I see !!-0 yielding false. Why is that?

Update: I now think most authors summing up falsy values either do not know about -0 being a value or mean by 0 both +0 and -0.


Solution

  • Simply put, the ECMAScript specification states that the boolean conversion of -0 results in false. This is stated in the table of conversions for the abstract operation ToBoolean, section 7.1.2.

    If argument is +0, -0, or NaN, return false; otherwise return true.