• NateNate60@lemmy.world
    link
    fedilink
    arrow-up
    41
    arrow-down
    2
    ·
    2 days ago

    This diagram is nonsense. JavaScript programmers know to simply never use == but to use === instead. Half of JavaScript is like this. Oh, there’s a feature, but it behaves in a super weird way so we don’t use it to avoid the weirdness.

    • ParlimentOfDoom@piefed.zip
      link
      fedilink
      English
      arrow-up
      9
      arrow-down
      1
      ·
      2 days ago

      As someone trying to learn Javascript, it just makes me mad that at this garbage heap of a language is so widely used.

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

        The problem is that you can’t break compatibility.

        Only in some exceptional cases. 🙃

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

            Personally, I’d love to break compatibility for better features and consistency. We should be able to declare the version at the top of the file or something. Nothing at the top = legacy crap. 🤷‍♂️ I dunno.

    • Denys Nykula@piefed.social
      link
      fedilink
      English
      arrow-up
      2
      ·
      2 days ago

      == has never, ever caused me a single issue. Parsing all server input with type-safe schemas makes sure that where I expect a string, I get a string; where I expect a number, I get a number. Bad data must result in an error before it reaches logic.

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

          I wonder how many millions of programmer man-hours have been wasted working around JavaScript’s design mistakes that could’ve been saved simply by putting Scheme or Python (which were actually being considered) in the browser instead.

        • Denys Nykula@piefed.social
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 day ago

          Opposite, living in a house of cards is when you blindly trust data that comes from user. Regardless of the language. eqeqeq isn’t in the recommended linting presets because if you end up needing it, you’re probably already in big trouble because of insecure software design.

            • Denys Nykula@piefed.social
              link
              fedilink
              English
              arrow-up
              0
              ·
              1 day ago

              Then where do you see the house of cards? What’s the practical difference between == and ===, when your app is type-checked and the inputs are safely parsed?

              • NateNate60@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                10 hours ago

                Because you don’t know whether you’ve actually type-checked everything and that your inputs are safely parsed. Part of defensive programming is to adopt multiple defences to prevent bad data from getting through, including avoiding ==.

    • 9point6@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      2 days ago

      IIRC modern linter rulesets generally just outright error if you do anything remotely like this.

    • diaphragmwp@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      2 days ago

      When I had to use JS I wrote JS 1.2 because why not. Fun how I had strings of numbers instead of actual numbers in some for loops, yet it all sort of functioned until something didn’t. I then decided to add Number() to random values just in case.