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

Aryan JogiAryan Jogi
2 min read

🧠 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:

  1. The relational comparison >= triggers numeric coercion.

  2. null becomes 0

  3. 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 equals undefinednot numbers, booleans, or strings.

👉 Final result: false


🧪 Example 4: undefined >= 0 // false

undefined >= 0 // false

Let’s walk through it:

  1. undefined coerces to NaN

  2. Comparing NaN >= 0always false

👉 Final result: false


🧪 Bonus Round: [null] == 0 // true

You didn’t ask, but here’s another curveball:

[null] == 0 // true

How?

  1. [null]'' (empty string after flattening)

  2. '' == 0true (because Number('')0)

👉 Final result: true


🎯 TL;DR — What to Remember

  • == and >= use different coercion rules

  • null becomes 0 in numeric comparisons (>=, >, etc.)

  • null only equals undefined with ==, not anything else

  • undefined turns into NaN in numeric operations

  • Arrays 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!


0
Subscribe to my newsletter

Read articles from Aryan Jogi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aryan Jogi
Aryan Jogi