37
Comments
  • 9
    Null is neither true or false or a number so no, you can’t compare it.

    Null is a black hole that can’t be measured but we know it’s there, well not there actually.
  • 6
    Lol ikr, it's almost like JavaScript runs on sorcery.
  • 7
    5 seconds of google would get you:

    "

    In Summary:

    Relational Comparison: if both values are not type String, ToNumber is called on both. This is the same as adding a + in front, which for null coerces to 0.

    Equality Comparison: only calls ToNumber on Strings, Numbers, and Booleans.
    "
  • 2
    I'd type a long reply, but since this gets posted I'll i stead say:

    TL;DR: ===
  • 0
    NaN === NaN = false is way worse...
  • 1
    Null is zero and negative
  • 1
    Null is Schrodinger's constant lul
  • 7
    Why are you comparing values with something that, by definition, is the lack of a value?

    You're the purple plastic pancake, not JS.
  • 0
    @olback its false in any language its the IEEE 754 specification that any NaN comparison is false.
  • 1
    Does null >= 0 return true as well
  • 0
    @olback parse your strings as numbers then
  • 0
    Hurray! A fellow Terminator user!
  • 2
    Nope don't blame it on JavaScript. I know it's not the best language but it's something you should know about the language
  • 1
    Seriously guys, null <= 0 evaluating to true is pretty fucked up.
  • 4
    Since nobody explains the stuff with larger than and smaller than:
    < and > check if the value is in the requested range
    I.e. Null > 0 is false because null is not in the range of greater than zero

    >= and <= check if the value is missing in the opposite range
    I.e. Null <= 0 is true because null is not in the range of greater than zero
  • 2
    @Astatos

    On one end I feel like that makes a lot of sense, but on another end I feel like that makes absolutely no fuckin' sense.
  • 0
    @C0D4 in js null is false (Boolean(null)==false)
  • 1
    @Grexius @Astatos is explaining what the operators do.

    When performing <= & and >= if both types are not strings, they have toNumber called on them.

    Thus 0 <= 0 = true

    This is all in the ECMA Script spec. Does no one read ;_;
  • 1
    So....try to query a db & it will also not know what to do with null values..

    & try looking for javascript fibonaccy function made of arrays & objects, only brackets nonsense but it works..
  • 0
Add Comment