• Lemminary@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    12 hours ago
    Explanation for nerds

    The reason is the JS compiler removes whitespace and introduces semicolons only “where necessary”.

    So writing

    function myFn() {
      return true;
    }
    

    Is not the same as

    function myFn() {
      return 
        true;
    }
    

    Because the compiler will see that and make it:

    function myFn() { return; true; }
    

    You big ol’ nerd. Tee-hee.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      6
      ·
      11 hours ago

      That’s terrifying, especially in JS where no type system will fuck you up for returning nothing when you should’ve returned a boolean.

      • Lemminary@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        6 hours ago

        Not wrong, but funnily enough, it’s a linting rule win. I’d go nuts if I didn’t have my type checks and my linters. My current L, though, is setting up the projects initially and dealing with the configuration files if I raw dog it, but that’s a problem with ESLint configs and the ecosystem as a whole having to deal with those headaches. So in the end, the JS devs got clever and shifted the blame to the tooling. 😅