• Alexstarfire@lemmy.world
    link
    fedilink
    arrow-up
    20
    arrow-down
    2
    ·
    9 months ago

    Unfortunately, it makes sense if you know what + means, which is concatenate. - is strictly a math function though.

    Not saying that makes this better. It just makes sense.

    • grue@lemmy.world
      link
      fedilink
      arrow-up
      26
      arrow-down
      3
      ·
      9 months 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
        6
        ·
        9 months 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
        ·
        9 months 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
          ·
          9 months 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.