• Victor
      link
      fedilink
      423 hours ago

      Classic people who don’t know how to code wat. Passing a number in place of a string argument because they don’t know what they’re doing.

      • @jjjalljs@ttrpg.network
        link
        fedilink
        3522 hours ago

        Javascript could throw an error to alert you that the input is supposed to be a string, like most languages would do.

        • Victor
          link
          fedilink
          -3
          edit-2
          19 hours ago

          But you’re calling a function specifically made for passing a string to an int… 😆 There’s gotta be some common sense somewhere here, guys.

          Still, it’s a very good point. JS should do this.

          I would suspect one reason it doesn’t do this is to be backwards compatible.

          • @listless
            link
            211 hours ago

            And god fucking forbid that common sense be in the language. Who the fuck needs a language with common sense, amirite?

        • @heavy@sh.itjust.works
          link
          fedilink
          English
          -321 hours ago

          Theoretically, Javascript is an untyped language, so there aren’t supposed to really be static types. Giving type errors in this situation would be against design.

      • Traister101
        link
        fedilink
        2322 hours ago

        It’s not a string argument though, it’s JS. You can argue it’s expected to be a string but like the rest of JS all you can know from the signature alone is that it takes an object. Hopefully your little ducky quacks the right way!

        • Victor
          link
          fedilink
          -119 hours ago

          It’s not a string argument though, it’s JS

          Huh? The code in the image is passing a number argument where there should be a string argument.

          And this function is specifically made to parse a string into an int. Apply common sense.

          • Traister101
            link
            fedilink
            -118 hours ago

            JavaScript doesn’t have typed parameters or variables. The function expects a string and does things in the function body which converts the object into a string. JS shares this behavior with all dynamically typed languages and it’s extremely useful in some contexts and extremely frustrating in others. It’s down to what it’s being used for. Dynamic languages make excellent scripting languages, see Python really just being a souped up shell lang

            • Victor
              link
              fedilink
              2
              edit-2
              9 hours ago

              The function expects a string and does things in the function body which converts the object into a string.

              … These are different words that describe exactly what I’m saying. I’m saying: in the place where there should be a string argument, because the function expects one, there is not a string argument, but a number argument. (Not an object like you keep saying.)

              I know all that stuff about dynamically typed languages. I’m just saying that the function is being used incorrectly here.

              • Traister101
                link
                fedilink
                016 hours ago

                You cannot have a string argument, arguments and variables in JS don’t have a type. All you have in JS is objects. Actual functions, like full on function foo(){} are still objects, like you can actually store data on the things.

                • Victor
                  link
                  fedilink
                  1
                  edit-2
                  9 hours ago

                  I think you confuse argument with parameter. You cannot specify the type of the parameter, but any argument you supply to a function in JS has a type. Every value in JS has a type, arguments included.

                  If I go:

                  const n = 0.0000005;
                  console.log(typeof n);
                  

                  The code above will print “number”. And you cannot assign n.foo = "metadata"; to this value of a primitive type. Not everything is an object.

                  Either way, arguments have types, values have types. The arguments in this case were of type “number”, when they should have been “string”.

      • @qqq@lemmy.world
        link
        fedilink
        13
        edit-2
        22 hours ago

        Could be a variable from somewhere else in the code. It should throw type error of some sort if it’s not going to handle a float correctly

        • Victor
          link
          fedilink
          119 hours ago

          Agreed, functions in general should do this, and some do. But it should probably be automatic. And the variable argument is a good one, a very good argument for TypeScript. ❤️