• Lemminary@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    10 days 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
      2
      ·
      10 days 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.