117

WHY U DO DIS JAVASCRIPT

Comments
  • 20
    I think it's because the <= and the >= operators look at being not the reciprocal. So if you're asking null <= 0 then JavaScript checks if null is contained in the set > 0. Since that's a no, then it's true.

    I might be way off though
  • 9
    @dongerzone absolutely you are damn right! Calculating the smaller or greater than is a whole lot of steps but it ends up just returning the default false and the <= operator is true if > is false
  • 2
    Well, according to Python 2.6, null (or None) is <= 0
  • 4
    The < operator and family create a total order, so every value will be either < or >= every other value. This allows safely sorting on < even when values are of mixed types.

    null < 1
    null > -1
  • 2
    @dongerzone huh... Good point. I would have not deduced it myself.
  • 1
    Which is why I like a little bit of type checking
  • 0
    Btw any particular reason for using opera?
  • 1
    @Faraaz it's basically Chromium plus a free VPN.

    Also I work with WebVR and Chrome had some issues with its flags. Easier to use opera than debug Chrome flags
  • 3
    ({} +1) is NaN
    {} +1 is 1

    Madness
  • 0
    Is there really no way to take a screenshot on Linux?
  • 0
    @devios1 There is, but phone is easier
  • 1
    I would ++, but that is a shocking photo, even for one inexplicably taken with a phone.
  • 0
    @Greggergalactic A null gets implicitly converted to a number? What the actual fuck?
  • 1
    @Greggergalactic The reason I hate weakly typed languages

    These sort of implicit type conversions in JavaScript is what makes me rant about it.

    Sadly, I cannot not use it because of its dominance in web development. My only other option is typescript and I'm not at the liberty of using it.

    A good programming language should at least throw a warning about this. Things like this is what will make developers pull out their hair because mathematically and logically, this is very illogical
  • 0
    ==, >= and =< cause type coercision. This is why JS the good parts and all books on JavaScript say you should use === of course you're out of luck for >= and <=. It would cause quite ambiguous behavior.
  • 0
    @Greggergalactic In Python 3.5, the result of "None >= 0" is a TypeError: unorderable types. I don't understand why JS will actually "change" a null value before comparing, that's terrible.

    Throwing an error or issuing a warning makes sense and that's how it should be.
  • 0
    I was like
    Okay
    Okay
    Okay
    Okay
    Okay
    Okay
    .... WTF?!?!?!
Add Comment