Course contentsShow
← JavaScript
Lesson 296 of 2,7238. Type CoercionFree lesson

The 0 == '0' but 0 == '' == false Triangle

Explaining the transitive equality paradox where 0 == '' and 0 == '0', but '' != '0'.

The 0 == '0' but 0 == '' == false Triangle

What you'll learn: Why three seemingly related comparisons create a bizarre logical paradox in JavaScript's loose equality.

The Strange Triangle

You might expect equality to be transitive—if A equals B and B equals C, then A should equal C, right? JavaScript's == operator breaks this rule spectacularly:

0 == '0'   // true
0 == ''    // true
'0' == ''  // false  ← Wait, what?!

How can 0 be equal to both '0' and '', yet those two strings aren't equal to each other?

Why This Happens

Each comparison triggers different coercion rules:

  • 0 == '0': The string '0' converts to the number 0, so you get 0 == 0 → true
  • 0 == '': The empty string converts to the number 0, so you get 0 == 0 → true
  • '0' == '': Both are already strings, so no coercion happens—JavaScript compares them character-by-character. They're literally different strings → false

The Analogy

Imagine asking "Is this the same?" while wearing different glasses for each comparison. Through "number glasses," both '0' and '' look like zero. But through "string glasses," '0' and '' are completely different words. You're not comparing the same way twice!

Why It Matters

This isn't just trivia—it's why experienced developers avoid == for comparisons. The coercion rules depend on which types are being compared, not just their values. Transitivity breaks because the coercion path changes.

Key Takeaway: Loose equality (==) isn't transitive because different type combinations trigger different coercion rules—always prefer === to avoid this paradox.