According to this table in the ECMAScript standard, string values that have length 0 should be evaluated as boolean false
.
How come, then, these statements evaluate to true
?
"\t" == false
" " == false
"\n" == false
" " == false
All those strings have a length greater than 0. For example:
While I understand that "0"
evaluates to false
because it can be coerced to a numeric 0
, I can't explain why these strings are falsey. What's going on?
(Obviously I can use ===
for a strict comparison, but in this case in my code, I need the loose comparison, however I wasn't expecting a non-empty string to be considered falsey.)