• Avid Amoeba
    link
    fedilink
    arrow-up
    206
    arrow-down
    1
    ·
    edit-2
    16 days ago

    This is too stupid so I had to check.

    Fuck me.

    • Gsus4@mander.xyz
      link
      fedilink
      arrow-up
      117
      ·
      edit-2
      16 days ago

      Hm, playing devil’s advocate, I think it is because the minus has not been defined as a string operation (e.g. it could pop the last char), so it defaults to the mathematical operation and converts both inputs into ints.

      The first is assumed to be a concat because one of the parcels is a string…

      It’s just doing a lot of stuff for you that it shouldn’t be in first place 🤭

      • Avid Amoeba
        link
        fedilink
        arrow-up
        43
        arrow-down
        1
        ·
        16 days ago

        Yup. It’s completely inconsistent in its interpretation of the + operator.

        • Gsus4@mander.xyz
          link
          fedilink
          arrow-up
          20
          ·
          edit-2
          16 days ago

          Yeah, I actually had to try 1+“11” to check that it didn’t give me 12, but thankfully it commutes it’s consistent 😇

          • palordrolap@fedia.io
            link
            fedilink
            arrow-up
            19
            ·
            16 days ago

            it commutes

            Maybe the behaviour with regard to type conversion, but not for the operation itself.

            “13”+12 and 12+“13” don’t yield the same result.

              • palordrolap@fedia.io
                link
                fedilink
                arrow-up
                4
                ·
                16 days ago

                Given it’s JavaScript, which was expressly designed to carry on regardless, I could see an argument for it returning NaN, (or silently doing what Perl does, like I mention in a different comment) but then there’d have to be an entirely different way of concatenating strings.

                  • palordrolap@fedia.io
                    link
                    fedilink
                    arrow-up
                    2
                    ·
                    15 days ago

                    You’re right. I’ve got too much Perl on the brain and forgot my roots. There is a language that does what you’re talking about with the ‘+’ operator: BASIC

                    Good luck getting the same thing retrofitted into JavaScript though. I can imagine a large number of websites would break or develop mysterious problems if this (mis)behaviour was fixed.

                • ChickenLadyLovesLife@lemmy.world
                  link
                  fedilink
                  English
                  arrow-up
                  5
                  ·
                  15 days ago

                  expressly designed to carry on regardless

                  I’m surprised they didn’t borrow On Error Resume Next from Visual Basic. Which was wrongly considered to be the worst thing in Visual Basic - when the real worst thing was On Error Resume. On Error Resume Next at least moved on to the next line of code when an error occurred; On Error Resume just executed the error-generating line again … and again … and again … and again …

      • 0x0@lemmy.zip
        link
        fedilink
        arrow-up
        12
        ·
        16 days ago

        It’s just doing a lot of stuff for you that it shouldn’t be in first place 🤭

        Kinda like log4j!

      • dalekcaan@lemm.ee
        link
        fedilink
        arrow-up
        13
        arrow-down
        1
        ·
        15 days ago

        Yeah, this looks dumb on the surface, but you’ve got bigger problems if you’re trying to do math with strings