Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Alternatively:

    console.log("woof")
    void function() { console.log("foo") }()
There really is only one ASI rule you need to remember [0] in practice: don't begin a new line with ( or [ if it's intended to be a new statement.

On this topic, it could so easily have been different; I found this interesting from Brendan Eich [1]:

> I wish I had made newlines more significant in JS back in those ten days in May, 1995. Then instead of ASI, we would be cursing the need to use infix operators at the ends of continued lines, or perhaps or brute-force parentheses, to force continuation onto a successive line. But that ship sailed almost 17 years ago.

> ...My two cents: be careful not to use ASI as if it gave JS significant newlines...

[0] this is technically a lie because everybody needs learn the other one whether they use semicolons or not: don't put a linebreak after the "return" keyword :) [1] https://brendaneich.com/2012/04/the-infernal-semicolon/



void blows up on Safari.


>There really is only one ASI rule you need to remember [0] in practice: don't begin a new line with ( or [ if it's intended to be a new statement.

Here's an even easier and clearer one: finish every statement with a semicolon.


  function hello() {
    var x = 0;
    return
    {
      x: x,
      y: y
    };
  };
Just putting semicolons where you think it can work won't help you. If you write javascript, you must know what the asi does. So semicolons or no semicolons is completely irrelevant.


This is precisely why I hate optional syntax, regardless of which way your preferences fall on this particular one.


Mindlessly inserting unnecessary syntax instead of learning the damn language. Hacker News should be proud of its lusers.


I don't have a photographic memory. If "learning the language" means rote memorization of an inconsistent set of rules for how the fucking code is parsed, then you're goddamn right I'd rather mindlessly insert a character that obviates that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: