0

I am a little confused by this:

0 > null  // gives me `false`
0 === null // gives me `false` - also
0 == null // is `false`

How come 0 >= null becomes true?

John Mutuma
  • 3,150
  • 2
  • 18
  • 31
  • When doing relational comparison between a number and `null`, the latter is coerced to the numeric `0`. – VLAZ Feb 08 '21 at 12:54
  • 1
    @Thomas `0 == null` doesn't compare them as strings. `null` is only equal to `undefined` using `==`. – VLAZ Feb 08 '21 at 12:56

1 Answers1

0

Comparisons convert null to a number, treating it as 0. That’s why 0 >= null is true.

Example:

0 === Number(null) // true
0 >= Number(null) // true

Edit: There's a difference on how null is handled in comparisons like >=, <=, >, < and how it is handled in equality checks like ===, == .

Tsvetan Ganev
  • 8,246
  • 4
  • 26
  • 43
P2GR
  • 54
  • 4