javascriptsemanticsautomatic-semicolon-insertion

Does automatic semi-colon insertion in JS affect for loops with the first { on a new line?


Will JS auto semi-colon insertion place a semi-colon at the end of for(...) like I've placed in the following example or is it safe to break the bracket onto a new line with for loops?

for(...);
{
   ...
}

I've found plenty of info saying what is affected, but nothing specific to my question, which leads me to believe it may not be affected, but I would like to find a concrete answer.

Personally, I prefer not to break onto a new line with brackets like this but the question has been raised ;)


Solution

  • Such a for loop is safe. Semicolons will never be inserted in places where they would create empty statements.