• oh god the reason is even stupider then I expected

      Because large numbers use the e character in their string representation (e.g., 6.022e23 for 6.022 × 1023), using parseInt to truncate numbers will produce unexpected results when used on very large or very small numbers. parseInt should not be used as a substitute for Math.trunc().

    • @tauonite@lemmy.world
      link
      fedilink
      0
      edit-2
      5 days ago

      Holy fuck that is long. When the documentation for the integer parsing function is 10 pages long, there’s something seriously wrong with the language

      • Lemminary
        link
        fedilink
        05 days ago

        Is it? I’ve seen longer articles for C# and not as many complaints about it.

        • @barsoap@lemm.ee
          link
          fedilink
          05 days ago

          Probably not an article about integer parsing, though. If the docs are that long, then because Microsoft does have a tendency to be overly verbose for things they think you need, just to have no docs for the stuff you actually need.

          For reference here’s the relevant rust docs.

    • @jsomae@lemmy.ml
      link
      fedilink
      0
      edit-2
      5 days ago

      Okay but this documentation is obviously wrong from the first sentence

      The parseInt() function parses a string argument and returns an integer of the specified radix

      Integers don’t have radices. It should read:

      The parseInt() function parses a string argument representing an integer of the specified radix and returns that integer.

      Either way, I still don’t understand the behaviour in the image. nvm, thanks m_f@discuss.online

    • @Zacryon@feddit.org
      link
      fedilink
      05 days ago

      I’d advise to always look into the corresponding documentation before using something from any library.

      • @pinball_wizard@lemmy.zip
        link
        fedilink
        05 days ago

        But I’m too busy being confused by the behaviors of libraries I previously didn’t read the documentation for, to read the documentation for every new library I adopt.

        (This is sarcasm…mostly.)