[X]

"0" Is Truthy And False

luljs still works

The string zero is truthy, and also loosely equal to false.

In 2026: Still works. A non-empty string is always truthy, so !!"0" is true and if ("0") runs its block. But "0" == false coerces both sides to the number 0, so they compare equal. The same value is true in a condition and equal to false in a comparison.

Where it came from: Truthiness tests string emptiness while == coerces to numbers, so the two disagree on "0". JavaScript Garden's types section covers both rules. JavaScript Garden

<script>
document.write('<p><code>!!"0"</code> is <b>' + (!!"0") + '</b> (a non-empty string is truthy)</p>');
document.write('<p><code>"0" == false</code> is <b>' + ("0" == false) + '</b> (both coerce to the number 0)</p>');
document.write('<p>Truthiness and == use different rules, so both are true.</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›