Semicolon in JavaScript


Semicolon in JavaScript

Semicolons in JavaScript are optional. When a semicolon is needed, it is added in the background. Semicolon Insertion is the name of the process that accomplishes this.

Automatic Semicolon Insertion Rules in JavaScript

It will automatically add a semicolon when it encounters the following scenarios while scanning source code:

  • code that breaks the current line in the following line (code can spawn on multiple lines)
  • the current block is closed when the source code file ends, and there is a return statement on its line
  • the line where the break statement is located.
  • the throw statement appears in its own line.
  • the continue statement appears in its own line.