Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. JavaScript

JavaScript

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
152 Posts 83 Posters 2 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cm0002@lemmy.worldC [email protected]
    This post did not contain any content.
    B This user is from outside of this forum
    B This user is from outside of this forum
    [email protected]
    wrote on last edited by [email protected]
    #128

    It's because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you're still using + for math or string concatenation in 2025, you're doing it wrong.

    H 1 Reply Last reply
    5
    • B [email protected]

      It's because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you're still using + for math or string concatenation in 2025, you're doing it wrong.

      H This user is from outside of this forum
      H This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #129

      I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

      Q _ B 3 Replies Last reply
      6
      • cm0002@lemmy.worldC [email protected]
        This post did not contain any content.
        calavera@lemmy.zipC This user is from outside of this forum
        calavera@lemmy.zipC This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #130

        It makes sense though

        Q Z P 3 Replies Last reply
        8
        • H [email protected]

          I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

          Q This user is from outside of this forum
          Q This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #131

          It's much better to make your own function that uses bitwise operations to do addition.

          function add(a, b) {
              while (b !== 0) {
                  // Calculate carry
                  let carry = a & b;
          
                  // Sum without carry
                  a = a ^ b;
          
                  // Shift carry to the left
                  b = carry << 1;
              }
              return a;
          }
          

          (For certain definitions of better.)

          1 Reply Last reply
          5
          • F [email protected]

            Not really, considering Typescript only adds static types to JS. It's not a different language, it's an extension.

            Q This user is from outside of this forum
            Q This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #132

            Since it needs to be compiled to JavaScript in order to be used, I kind of consider it a different language. Yes, it's a strict superset of JavaScript, but that makes it different.

            F 1 Reply Last reply
            5
            • D [email protected]

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

              K This user is from outside of this forum
              K This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #133

              Better than doing physics with strings

              1 Reply Last reply
              1
              • M [email protected]

                That's also my understanding: "Javascript is great because you can use other languages and then transpile them to JS."

                K This user is from outside of this forum
                K This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #134

                Oh man machine language is so good, literally the best actually

                1 Reply Last reply
                2
                • H [email protected]

                  I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

                  _ This user is from outside of this forum
                  _ This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #135

                  The correct way to do it is to load a 500mb library that has an add function in it.

                  B 1 Reply Last reply
                  14
                  • calavera@lemmy.zipC [email protected]

                    It makes sense though

                    Q This user is from outside of this forum
                    Q This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #136

                    https://en.wikipedia.org/wiki/Stockholm_syndrome

                    M 1 Reply Last reply
                    26
                    • S [email protected]

                      So, just don’t use JavaScript?

                      S This user is from outside of this forum
                      S This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #137

                      Yeah! Wasm is a thing. At least rust and go are pretty neat in the browser lately.

                      We should leave that pile of semantics and just go further with web development

                      1 Reply Last reply
                      0
                      • Q [email protected]

                        Since it needs to be compiled to JavaScript in order to be used, I kind of consider it a different language. Yes, it's a strict superset of JavaScript, but that makes it different.

                        F This user is from outside of this forum
                        F This user is from outside of this forum
                        [email protected]
                        wrote on last edited by [email protected]
                        #138

                        That's your prerogative, but it honestly doesn't make sense. Typescript adds almost no functionality to JS (and the few pieces it adds are now considered mistakes that shouldn't be used anymore). It only focuses on adding typing information, and in the future you'll be able to run TS that doesn't use those few added features as JS (see the proposal).

                        You can also add the TS types as comments in your JS code, which IMO shows that it's not a different language.

                        1 Reply Last reply
                        1
                        • M [email protected]

                          That's also my understanding: "Javascript is great because you can use other languages and then transpile them to JS."

                          F This user is from outside of this forum
                          F This user is from outside of this forum
                          [email protected]
                          wrote on last edited by [email protected]
                          #139

                          JS itself is great, I prefer it to most other languages due to the flexibility that it allows. Adding types through TS to safeguard against footguns doesn't mean you're not still using JS. You can also add the types using comments instead if you prefer it, which means you're actually writing raw JS.

                          1 Reply Last reply
                          0
                          • calavera@lemmy.zipC [email protected]

                            It makes sense though

                            Z This user is from outside of this forum
                            Z This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #140

                            .... It does?

                            1 Reply Last reply
                            6
                            • _ [email protected]

                              The correct way to do it is to load a 500mb library that has an add function in it.

                              B This user is from outside of this forum
                              B This user is from outside of this forum
                              [email protected]
                              wrote on last edited by [email protected]
                              #141

                              Point taken but the one I use is only ~200k for the whole package, ~11k for the actual file that gets loaded

                              1 Reply Last reply
                              0
                              • H [email protected]

                                I know nothing about javascript, what is wrong with using + for math? perhaps naively, I'd say it looks suited for the job

                                B This user is from outside of this forum
                                B This user is from outside of this forum
                                [email protected]
                                wrote on last edited by [email protected]
                                #142

                                The native arithmetic operators are prone to floating point rounding errors

                                1 Reply Last reply
                                1
                                • supervisor194@lemmy.worldS [email protected]

                                  So all you've mustered is some lame-ass ad-hominem? Have a good day

                                  S This user is from outside of this forum
                                  S This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #143

                                  No, it just so happens I have a minute to talk about our lord and saviour JS. What is His holy and sacred mission?

                                  supervisor194@lemmy.worldS 1 Reply Last reply
                                  0
                                  • Q [email protected]

                                    https://en.wikipedia.org/wiki/Stockholm_syndrome

                                    M This user is from outside of this forum
                                    M This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #144

                                    This here is my absolute favorits way to diss someone. Send the a wikipeda link and bam!

                                    rivalarrival@lemmy.todayR 1 Reply Last reply
                                    4
                                    • S [email protected]

                                      No, it just so happens I have a minute to talk about our lord and saviour JS. What is His holy and sacred mission?

                                      supervisor194@lemmy.worldS This user is from outside of this forum
                                      supervisor194@lemmy.worldS This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by [email protected]
                                      #145

                                      Ah, you're a troll. I see. Blocked.

                                      S 1 Reply Last reply
                                      0
                                      • supervisor194@lemmy.worldS [email protected]

                                        Ah, you're a troll. I see. Blocked.

                                        S This user is from outside of this forum
                                        S This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #146

                                        You asked for it, smart ass

                                        1 Reply Last reply
                                        0
                                        • K [email protected]

                                          That is just the tip of the iceberg:

                                          https://whatthefsharp.com/JavaScript/3

                                          A This user is from outside of this forum
                                          A This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #147

                                          so plus coerces into string if not number, was that so hard?

                                          1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups