
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What are the rules for JavaScript's automatic semicolon insertion (ASI)?
JavaScript’s automatic semicolon insertion (ASI) is to insert missing semicolons. The following statements are affected by automatic semicolon insertion −
empty statement var statement expression statement do-while statement continue statement break statement return statement throw statement
The rules are in the following specification −
- When, as a Script or Module is parsed from left to right: A token is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token only if one or more of the following conditions becomes true −
- Offending token is }.
- Previous token is ) and the inserted semicolon would then be parsed as the terminating semicolon of a do-while statement (13.7.2).
- End of the input stream of tokens is encountered and therefore parser is unable to parse the input token stream as a one complete ECMAScript or a Module, then a semicolon is automatically inserted.
- Token is encountered that is allowed by some production of the grammar, but the production is a restricted production and the token would be the first token for a terminal or nonterminal immediately following the annotation.
- Related Articles
- What are the identity rules for regular expression?
- What are the basic rules for JavaScript parameters?
- What are the basic scoping rules for python variables?
- What are the golden rules for handling your money?
- What are the rules for naming classes in C#?
- What are the rules for calling the superclass constructor C++?
- What are the basic rules for defining variables in C++?
- What are the rules for a functional interface in Java?
- What are the rules for the Subscriber interface in Java 9?
- What are the rules for the Subscription interface in Java 9?
- What are the rules for the Publisher interface in Java 9?
- What are the rules for writing the symbol of an element?
- What are automatic modules in Java 9?
- What are the scoping rules for lambda expressions in Java?\n
- What are the rules for local and global variables in Python?

Advertisements