JavaScript syntax: Difference between revisions

Content deleted Content added
Kelti (talk | contribs)
m Dead links
Line 40:
|year=2006}}</ref>
 
There are two issues: five tokens can either begin a statement or be the extension of a complete statement; and five restricted productions, where line breaks are not allowed in certain positions, potentially yielding incorrect parsing.<ref name="inimino" />
 
The five problematic tokens are the open parenthesis "<code>(</code>", open bracket "<code>[</code>", slash "<code>/</code>", plus "<code>+</code>", and minus "<code>-</code>". Of these, the open parenthesis is common in the [[immediately-invoked function expression]] pattern, and open bracket occurs sometimes, while others are quite rare. TheAn example given in the spec<!-- The blog is not a spec[ification] --> is:<ref name="inimino" />
 
<syntaxhighlight lang="javascript">
Line 53:
with the suggestion that the preceding statement be terminated with a semicolon.
 
Some suggest instead the use of ''leading'' semicolons on lines starting with '<code>(</code>' or '<code><nowiki>[</nowiki></code>', so the line is not accidentally joined with the previous one. This is known as a '''defensive semicolon''', and is particularly recommended, because code may otherwise become ambiguous when it is rearranged.<ref name="inimino">"[http://inimino.org/~inimino/blog/javascript_semicolons JavaScript Semicolon Insertion: Everything you need to know]", [http://inimino.org/~inimino/blog/ ~inimino/blog/], Friday, 28 May 2010</ref><ref>"[http://mislav.uniqpath.com/2010/05/semicolons/ Semicolons in JavaScript are optional]", by Mislav Marohnić, 7 May 2010</ref> For example:
 
<syntaxhighlight lang="javascript">