Someone had to do this before the riots started.

  • bitcrafterOP
    link
    fedilink
    arrow-up
    3
    ·
    1 day ago

    Ah, but you see, JavaScript is not so straightforward. It tries to help you by automatically inserting missing semicolons, but the approach that it uses is that it will insert them in the first place where doing so would make the code parse. This, unfortunately, means that semicolons are often inserted in places where you were not expecting them, so the advice is to always include them manually yourself so that you are never unpleasantly surprised.

    • anton@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      2
      ·
      8 hours ago

      This, unfortunately, means that semicolons are often inserted in places where you were not expecting them

      example:

      ()=>{
        return {k:"v"}; // returns the object
      }
      ()=>{
        return      // returns undefined 
          {k:"v"};  // unreachable 
      }
      

      so the advice is to always include them manually yourself so that you are never unpleasantly surprised.

      The example will be unpleasantly surprising, no matter where you put semicolons.