• grue@lemmy.world
    link
    fedilink
    arrow-up
    30
    arrow-down
    3
    ·
    edit-2
    3 days ago

    It is ‘comprehensible’ in the sense that it’s possible to figure out how it happened, but it absolutely does not “make sense” in terms of being a reasonable language design decision. It’s 100% incompetence on the part of the person who created Javascript.

    • Alexstarfire@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      3 days ago

      I mean, I’d never try to do this anyway because if the types aren’t the same unexpected things can happen. That’s like programming 101.

    • Fushuan [he/him]@lemm.ee
      link
      fedilink
      arrow-up
      2
      ·
      3 days ago

      It makes perfect sense if the Lang objective is to fail as little as possible. It picks the left side object, checks if the operand is a valid operand of the type. If it is, it casts the right variable into that type and perform the operand. If it isn’t, it reverses operand positions and tries again.

      The issue here is more the fact that + is used both as addition and as concatenation with different data types. Well, not an issue, just some people will complain.

      • grue@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        2 days ago

        Computing a nonsensical result is itself a failure. Continuing to run while avoiding giving an error in that case accomplishes nothing but to make the program harder to debug.