• Tenkard@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago
    1. You can call it “Java” to enrage other programmers
    2. You can compare numbers against strings without wasting time converting them
  • udon@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago
    1. it’s easy to make fun of
    2. it makes every other programming language look better in comparison
    • Drusenija@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      What’s even wilder is if you look at the code of that package, all it does is include the is-odd package and then return !is-odd. And the is-odd package isn’t much better, it does some basic checks on the input and then returns n % 2 === 1.

      • NotAViciousCyborg@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I thought I was missing something. JS is one of my main languages and I always just write the is-odd function myself since it’s like 10 characters. It boggles the mind that is-even has 176k weekly downloads

        • kevincox@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          To be fair having a name can make things easier to read. I get that i % 2 == 0 is a common pattern and most programmers will quickly recognize what is happening. But isEven(i) is just that much easier to grok and leaves that brainpower to work on something else.

          But I would never import a package for it. I would just create a local helper for something this trivial.

          • NotAViciousCyborg@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            1 year ago

            Exactly what I would do if I had to reuse it, especially now since I know that adding a package would actually add 2. It all just seems so…inefficient

            • kevincox@lemmy.ml
              link
              fedilink
              arrow-up
              1
              ·
              1 year ago

              Even if the code isn’t reused adding names to sub-expressions can be very valuable. Often times I introduce new functions or variables even if they are only used once so that I can give them a descriptive name which helps the reader more quickly understand what is happening.

        • toastal@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          1 year ago

          This isn’t speaking, but writing (or typing). Using ‘correct’ spelling & grammar helps ESL speakers read the language as well as those relying on text translation software. Some folks make typos & it’s fine to make mistakes but it’s also strange to act like it’s just as easy to understand. Apostrophes have a specific meaning & many folks rely on them for understanding.

          I’m learning a foreign language now & I can tell you it is a massive stumbling block when you run into what you think is a new word, but is ‘just’ a misspelling.

          My issue with this account is not its corrections, but if you want to be the correction bot, at least get the typography right too. ' is as ASCII holdover & it should be .

  • SGG@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago
    1. It runs in browsers
    2. If you hate your co-workers, then they will also feel your pain.
      • palordrolap@kbin.social
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Depends on how you define “scripting language”.

        Older techs remember when it was only browser-based and they thought of, and perhaps still think of, “scripting languages” as something that would run from some command-line or another. Starting a GUI browser to run a mere script was a ridiculous concept. (There was also that JavaScript had no filesystem access. At least initially. And then it became a gaping security hole, but I digress.)

        Today, there exist command-line accessible versions of JavaScript but even there (I figure) most people wince and choose anything else instead. Maybe even Perl.

        But another definition of “scripting language” is “(any) interpreted programming language” and where it runs is unimportant.

        From that perspective, sure, JavaScript qualifies. And so does QBASIC.

        • shastaxc@lemm.ee
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          A script is just a file that can execute a series of commands without the need to compile

    • inetknght@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      It’s also not a scripting language.

      It definitely is a scripting language.

      hello-world.js:

      #!/usr/bin/env node
      
      console.log("Hello world");
      

      Your favorite command line tool:

      chmod +x ./hello-world.js
      ./hello-world.js
      

      You just need to install npm, eg via apt-get install npm.

  • Fargeol@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    1 year ago

    1 - Easiest way to run a script in your browser
    2 - Always finds its way if inputs are bad
    Nan - undefined

      • joneskind@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        1 year ago

        When my console throws a NaN I kinda think of it as an Halloween kid receiving a fruit instead of a candy. They won’t say “That’s a fruit”. They’ll say “That’s not a treat”.

        I’m personally pissed more often by a falsy 0.

        Did you know that early analog computers would literally explode when asked to divide by 0?

        Now computers just say “Hey stupid, that shit is not even a Number in a mathematical sense, but sure I’ll add one to it.” instead of “Why would you kill me like this?”

        You can’t really define Infinity as a number, yet it is part of their world.

        So typeof NaN === ‘number’ totally makes sense in that regard.

        If you ever worked with arrays of dates, don’t judge NaN too harshly.

        • Skullgrid@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          Falsy zero? What’s wrong with that, 1 is true and 0 is false. I thought that was standard logic?

          • joneskind@lemmy.world
            link
            fedilink
            arrow-up
            0
            ·
            1 year ago

            in javascript a property is truthy if it exists

            myThing.property = "some string"
            
            if (myThing.property) { // true
              // do something
            }
            

            It works with everything except of course for falsy values

            myThing.number = someNumberThatShouldNotBeEqualToZero
            
            if (myThing.number) {
              // do something very important with that number that should not be equal to zero
            }
            
            // This can fail at anytime without warning
            

            So you’ve got to be extra careful with that logic when you’re dealing with numbers.

            I am not saying it’s wrong though. I’m saying it’s often annoying.

            • Skullgrid@lemmy.world
              link
              fedilink
              arrow-up
              0
              ·
              1 year ago

              ah ok , I think I write this a bit more verbose when using other languages, instead of

              if(thing)
              {
                 stuff;
              }
              
              

              I do

              
              if(thing != null)
              {
                 stuff;
              }
              

              so checking for numbers being truthy & existing didn’t seem like an issue

              • joneskind@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                1 year ago

                In the case of a non-existing property, the value would be undefined rather than null.

                And while == and != exist in JavaScript, most linters will throw an error and require a === and !== instead as they should be avoided.

                null == undefined // true
                null === undefined // false
                

                Besides, null is a perfectly valid value for a property, just as 0. Working with API Platform, I couldn’t tell the number of times I used this kind of statement:

                if (property || property === null) {
                  // do some stuff
                }
                

                Probably just as much as

                if (property || property === 0) {
                  // do some stuff
                }
  • ☆ Yσɠƚԋσʂ ☆@lemmy.ml
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    1 year ago

    The part that always gets me is when people choose Js for the backend. Like I get that it’s the default thing that works on the frontend, so there’s some rationale why you might not want to transpile to it from another language. On the backend though, there are so many far better option, why would you willingly go with Js, especially given that you’re now forced to do all your IO async.

    • 31337@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Server side rendering looks like it could be useful. I imagine SSR could be used for graceful degradation, so what would normally be a single page application could work without Javascript. Though, I’ve never tried SSR, and nobody seems to care about graceful degradation anymore.

      • ☆ Yσɠƚԋσʂ ☆@lemmy.ml
        link
        fedilink
        arrow-up
        0
        arrow-down
        1
        ·
        1 year ago

        Most pages tend be just documents and fairly simple forms. Making SPAs and then having to worry about SSR is just making a Rube Goldberg machine in most cases. I think something like HTMX is a much better approach in most cases. You keep all your business logic server side, send regular HTML to the client, and you just have a little bit of Js on the frontend that knows how to patch in chunks of HTML in the DOM as needed. Unless you have a highly interactive frontend, this is a much better approach than making a frontend with something like React and adding all the complexity that goes with it.

      • ☆ Yσɠƚԋσʂ ☆@lemmy.ml
        link
        fedilink
        arrow-up
        0
        arrow-down
        1
        ·
        1 year ago

        No I meant having to do async as opposed to having threads like you would in Java for example. In vast majority of cases a thread pool will work just fine, and it makes your code far simpler. Typically, Java web servers will have a single thread that receives the request and then dispatches it to the pool of workers. The JVM is then responsible for doing the scheduling between the threads and ensuring each one gets to do work. You can do async too, but I’ve found threads scale to huge loads in practice.