• Tenkard@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    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
  • SGG@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    7 months ago
    1. It runs in browsers
    2. If you hate your co-workers, then they will also feel your pain.
  • heavyboots@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    7 months ago

    Browsers love it!

    Practically anything you write will execute without all that scope and well formed statements nonsense.

    Mind you, number 2 is also its biggest flaw as well, but…

  • udon@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    7 months ago
    1. it’s easy to make fun of
    2. it makes every other programming language look better in comparison
  • Fargeol@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    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

      • joneskind@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        6 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
          0
          ·
          6 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
            0
            ·
            6 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
              0
              ·
              6 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

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

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

    • kamen@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

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

    • Drusenija@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      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
        0
        ·
        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

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

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

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

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

        • kevincox@lemmy.ml
          link
          fedilink
          arrow-up
          0
          ·
          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
            0
            ·
            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
              0
              ·
              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
                0
                ·
                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.

  • Skullgrid@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    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.

  • ☆ Yσɠƚԋσʂ ☆@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    7 months 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.

  • kevincox@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    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).