• Drusenija@lemmy.world
      link
      fedilink
      arrow-up
      82
      ·
      7 months 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
        27
        ·
        7 months 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
          19
          ·
          7 months 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
            10
            ·
            7 months 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
              11
              ·
              7 months 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.

              • NotAViciousCyborg@lemmy.world
                link
                fedilink
                arrow-up
                3
                ·
                7 months ago

                Yeah, I do that with pretty much every separate operation in c# since our solutions are pretty big. Most of my JS scripts are just done in ServiceNow which are separated and named appropriately.

        • gaael@lemmy.world
          link
          fedilink
          arrow-up
          7
          ·
          7 months ago

          Also there are 40-something packages depending on it, so I guess it gets pulled automatically when they are used.

        • Aqarius@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          7 months ago

          If youre lazy/busy enough, doing basic checks on the input is enough boilerplate to package out.

    • kamen@lemmy.world
      link
      fedilink
      arrow-up
      10
      ·
      7 months ago

      This must be a “hold my beer” kind of joke and someone wanting to see how far they can take it.

  • udon@lemmy.world
    link
    fedilink
    arrow-up
    71
    arrow-down
    3
    ·
    7 months ago
    1. it’s easy to make fun of
    2. it makes every other programming language look better in comparison
  • SGG@lemmy.world
    link
    fedilink
    English
    arrow-up
    63
    ·
    7 months ago
    1. It runs in browsers
    2. If you hate your co-workers, then they will also feel your pain.
  • Tenkard@lemmy.ml
    link
    fedilink
    arrow-up
    62
    arrow-down
    1
    ·
    7 months ago
    1. You can call it “Java” to enrage other programmers
    2. You can compare numbers against strings without wasting time converting them
      • nxdefiant@startrek.website
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        7 months ago

        JavaScript: :wide eyed and smiling: Sure why not! You’re the boss!

        Python: Sighing and downing half a bottle of Advil: Sure. Why not, you’re the boss.

    • TrickDacy@lemmy.world
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      7 months ago

      If you’re living in 2002 and not using the strict equality operator, that’s on you

      • luciferofastora@lemmy.zip
        link
        fedilink
        arrow-up
        3
        arrow-down
        2
        ·
        7 months ago

        But what if I don’t want strict comparison? What if my frontend contains a text field for a numeric input and I wanna manually check against each possible valid input value if (input_val == 1) {...} else if (input_val == 2) {...} else if... without having to convert it first or check that it’s actually a number or fix my frontend?

        (I’m sure there are valid use cases for non-strict comparison, I just can’t think of one right now)

        • PrettyFlyForAFatGuy@feddit.uk
          link
          fedilink
          arrow-up
          4
          ·
          edit-2
          7 months ago

          why wouldn’t you just convert inline? (Number(input_val) === 2)

          Converting would mean you could use a switch statement with your example rather than an if else ladder

          switch(Number(input_val)) {
            case 1:
              doTheFirstThing();
            break;
            case 2:
              doTheSecondThing();
            break;
            case 3:
              doTheThirdThing();
            break;
          }
          
          • luciferofastora@lemmy.zip
            link
            fedilink
            arrow-up
            1
            arrow-down
            2
            ·
            edit-2
            7 months ago

            If you’re looking for good code, you missed the point of my comment 😄

            If I was looking for an enumeration of valid inputs, I’d make it a selection box rather than a text field that’s supposed to contain a number and give the selections reasonable names. If I want an integral quantity, I’d use a number input field.

            If I have no control over the frontend, that means I’m writing a backend in JS for a bullshit frontend, and no amount of good coding practice is going to salvage this mess.

            I’m also blessedly far away from WebDev now. I work in Data Analytics and if I ever have to do any of this for a living, something has gone very wrong.

            Converting texts into numbers or dates still haunts me though - fuck text inputs for numbers and dates.

        • toastal@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          7 months 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 .

  • BeefPiano@lemmy.world
    link
    fedilink
    English
    arrow-up
    56
    ·
    7 months ago
    1. It has the simplest multi-threaded implementation: no threads!
    2. You can goof off while your build system takes 20 minutes to rebuild a non-compiled language
  • Fargeol@lemmy.ml
    link
    fedilink
    arrow-up
    42
    arrow-down
    1
    ·
    edit-2
    7 months ago

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

      • kevincox@lemmy.ml
        link
        fedilink
        arrow-up
        10
        ·
        7 months ago

        To be fair, this is actually reasonable. But it does look stupid on the face of it.

      • joneskind@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        7 months 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
          1
          ·
          7 months 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
            1
            ·
            7 months 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
              1
              ·
              7 months 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
                7 months 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
                }
  • Skullgrid@lemmy.world
    link
    fedilink
    arrow-up
    46
    arrow-down
    5
    ·
    7 months ago

    I am forced to try to get a JS certification.

    I am reaching the end of my rope, and starting to think of maybe putting my neck into one.

    Isaac Newton said that we see far because we stand on the shoulders of giants.

    Javascript is like standing on the shoulders of dwarves with brittle bone disease.

    • howrar
      link
      fedilink
      arrow-up
      5
      ·
      7 months ago

      Standing on the shoulder of dwarves hiding deep underground

  • vocornflakes@lemmy.world
    link
    fedilink
    English
    arrow-up
    40
    arrow-down
    2
    ·
    7 months ago
    1. Ubiquitous; insane amount of libraries and probably some of the best documentation of any language
    2. JS lambda function syntax is nice
    • ByteJunk@lemmy.world
      link
      fedilink
      arrow-up
      29
      arrow-down
      1
      ·
      7 months ago

      I spent way too long today figuring out why my app was doing something that it’s NOT supposed to do on weekends.

      I read Luxon’s docs (pretty cool lib tbh) again and again, and tried everything I could think of to get isWeekend to return a sane result.

      Turns out I was pulling a somewhat older version of Luxon, where isWeekend didn’t exist. In any sane language, I expect I’d get a huge warning about a property that doesn’t exist, but alas…

      Typescript helps me keep my sanity, but juuuuust barely.

      • mynameisigglepiggle@lemmy.world
        link
        fedilink
        arrow-up
        21
        arrow-down
        1
        ·
        edit-2
        7 months ago

        If isWeekend doesn’t exist, then the weekend doesn’t exist, so it’s naturally false.

        That’s why JavaScript gets pushed so hard - it’s part of the capitalist agenda to keep us working 7 days a week

          • shastaxc@lemm.ee
            link
            fedilink
            arrow-up
            2
            arrow-down
            1
            ·
            edit-2
            7 months ago

            Falsy* because it was undefined

            However, their IDE should have highlighted it as an unknown property. Guess this guy is coding in notepad or vi.

            • humbletightband@lemmy.dbzer0.com
              link
              fedilink
              arrow-up
              2
              ·
              7 months ago

              Yep, thanks for correcting me. In fact, if they write something like

              if (day.isWeekend) {...}
              

              The block will never be executed with the old version of library

              • shastaxc@lemm.ee
                link
                fedilink
                arrow-up
                2
                ·
                7 months ago

                Yeah that’s exactly what I think happened to him. He needs a better IDE and/or needs to stop copy/pasting code from stackoverflow or documentation that doesn’t match his library version.

                • ByteJunk@lemmy.world
                  link
                  fedilink
                  arrow-up
                  1
                  arrow-down
                  1
                  ·
                  7 months ago

                  My dude, you need to understand that all that anger and resentment, it is not you. It’s the years of JavaScript poisoning your mind.

                  In any case, that goes to my point. I would have to be saved by my IDE, when any sane language will blow up in your face as soon as you try to run it.

  • kevincox@lemmy.ml
    link
    fedilink
    arrow-up
    23
    arrow-down
    3
    ·
    7 months ago
    1. Is available to be used in website scripting.
    2. Not quite as full of footguns as PHP (although it is close).