The Hidden Truth Behind null >= 0 and Other JS Logic Traps

🧠 Why null >= 0
is true and other JavaScript WTFs 🤯
If you've ever seen a JavaScript comparison and thought,
"Okay... that's just broken."
You're not wrong.
JavaScript’s type coercion plays by its own set of rules — and they’re not always obvious.
Let’s walk through some lesser-known but equally quirky comparisons — and break them down, step by step.
🧪 Example 1: null >= 0
// true
Wait, what?!null
is not equal to 0
, but it's greater than or equal to it?
Let’s break it down:
null >= 0
Step-by-step:
The relational comparison
>=
triggers numeric coercion.null
becomes0
So it becomes:
0 >= 0 // true
👉 Final result:
true
Wild.
🧪 Example 2: null > 0
// false
Here’s the twist:
null > 0 // false
Still using numeric coercion:
Number(null) > 0
0 > 0 // false
👉 Final result: false
Same coercion rule, but now it's a strict "greater than."
🧪 Example 3: null == 0
// false
This one feels inconsistent:
null == 0 // false
Why?
Because ==
uses different coercion logic than <
or >=
.
null
only loosely equalsundefined
— not numbers, booleans, or strings.
👉 Final result: false
🧪 Example 4: undefined >= 0
// false
undefined >= 0 // false
Let’s walk through it:
undefined
coerces toNaN
Comparing
NaN >= 0
→ always false
👉 Final result: false
🧪 Bonus Round: [null] == 0
// true
You didn’t ask, but here’s another curveball:
[null] == 0 // true
How?
[null]
→''
(empty string after flattening)'' == 0
→true
(becauseNumber('')
→0
)
👉 Final result: true
🎯 TL;DR — What to Remember
==
and>=
use different coercion rulesnull
becomes0
in numeric comparisons (>=
,>
, etc.)null
only equalsundefined
with==
, not anything elseundefined
turns intoNaN
in numeric operationsArrays get coerced to strings or numbers based on context
💡 Pro Tip:
If it feels broken… it probably is — but there’s logic behind the madness.
When in doubt, break it down like the engine does: coercion → comparison.
Or better yet:
Use
===
and avoid this rabbit hole altogether.
💬 Bonus:
What’s your favorite WTF comparison in JavaScript?
👇 Drop it in the comments!
Subscribe to my newsletter
Read articles from Aryan Jogi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
