11
hitko
4y

Is apple a fruit? Yes.
Is orange a fruit? Yes.
Is apple an orange? No.

Does apple equal a fruit? No.
Does orange equal a fruit? No.

If you're capable of understanding this, then WHY IS IT IT SO DAMN HARD TO UNDERSTAND 0 == ""?

Comments
  • 2
    Reading the manual helps.

    "If Type(x) is Number and Type(y) is String,
    return the result of the comparison x == ToNumber(y)."

    https://ecma-international.org/ecma...
  • 4
    But did you know that chilli pepper is a fruit
  • 4
    Is apple instance of fruit? Yep.
  • 1
    @melezorus34 That's where you may be wrong good sir. The actual fruit of an apple is the apple core.
  • 1
    Class chains apply on instanceof 😛
  • 1
    @melezorus34 Indeed, an Accessory Fruit does not know about seeds so it cannot be a subclass of Fruit, but the instanceOf still works. We have proven that JS is not class oriented then.
  • 4
    Is mayonnaise an instrument?
  • 1
    "is a" is not the same as "equals to".
    It looks like your example is just confirming the wrongness of JS.
  • 0
    @Lensflare You mean like the is operator in C#? That would be typeof in js.
  • 1
    @theuser C# does also have typeof() 🙂
  • 0
    Think I get what you're trying to convey, but == is wrong as a comparison operator.

    defining, mathematically, how null, 0, "", [], {} and other empty types are exactly empty other than just saying "they just are", is difficult.

    Or read this 1980 paper, a foundational work on type theory around implicit conversions in imperative languages: http://cs.cmu.edu/afs/cs/...

    Isn't type theory fun?

    Anyway, my glass of cognac ∈ ⊥

    Wait no, that's impossible, something can't be part of nothing.

    Anyway, I'm ∈ drunk people, so my brain is ⊥
Add Comment