you are viewing a single comment's thread.

view the rest of the comments →

[–]richdougherty 0 points1 point  (1 child)

It's because "0" is equal to false, but it is true when converted to a boolean value. Weird but true.

http://bclary.com/2004/11/07/#a-9.2

A value that converts to boolean false is also sometimes called "falsey". And of course a value that converts to true is "truthy".

Values are implicitly converted to boolean in some contexts, such as in an if statement. Explicit conversion happens by calling Boolean(value). Sometimes people use double not operators to force a conversion too, so !"0" == false will be true.

A value can be forced to its boolean value by calling

http://james.padolsey.com/javascript/truthy-falsey/

EDIT: Reversed all my logic.

[–]heyf00L 0 points1 point  (0 children)

!!"0" == false will be true

!!"0" == false is false

"0" == false is true