0

I just discovered this oddity in JavaScript:

null > 0
// false

null == 0
//false

null >= 0
//true

Why does the final test evaluate to true? It seems more than a little counterintuitive.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
  • See: https://stackoverflow.com/questions/2910495/why-null-0-null-0-but-not-null-0 – Mark Apr 18 '21 at 05:27
  • https://stackoverflow.com/questions/13407544/why-is-null-in-javascript-bigger-than-1-less-than-1-but-not-equal-to-0#:~:text=2%20Answers&text=When%20you%20compare%20null%20for,%2C%20%3E%20%2C%20and%20%3E%3D%20. – Daniel Krom Apr 18 '21 at 05:27
  • Thanks both! I did search, did not find. – Steve Bennett Apr 18 '21 at 05:28
  • The >= operator behaves differently for some reason. The == operator converts null to undefined while comparing. – Visakh Vijayan Apr 18 '21 at 05:35
  • I am not certain, but I think it is spawned of laziness. It could be that the algorithm only perfoms one check. If null < 0 is false, then null >= 0 is true. – Vbudo Apr 18 '21 at 07:21

0 Answers0