ASI
JavaScript automatically inserts semicolons (;
) in certain cases, but not always. Understanding ASI is critical to avoid subtle bugs. Also, it is great to make unique payloads to bypass restrictions. Here are the key rules, remember them for future reference:
When ASI Adds Semicolons
At the End of a File
After a Line Break (if the next line is invalid syntax)
let x = 1 // ASI adds `;` let y = 2 // ASI adds `;`
before
}
,continue
,break
,return
,throw
, oryield
{let x=1}{let x=3}{let x=null}
When ASI Does Not Add Semicolons
If the next line starts with
(
,[
,`
,/
,+
, or-
After
++
or--
In
for
Loops
Last updated