Automatic semi-colon insertion (Definition)

The action of adding semi-colons where they have been omitted.

Availability:

ECMAScript edition - 2

A semi-colon explicitly placed in the source text must terminate certain statements. Your JavaScript interpreter may help by adding some automatically, but this may not work as you expect. As they say, "Your mileage may vary".

Semi-colons are used to explicitly terminate certain keywords so that the parser can determine exactly where the fragment of code begins and ends. The semi-colon removes the ambiguity about how a piece of code is intended to execute.

Line terminators greatly affect the automatic semi-colon insertion process.

The following statements must have trailing semi-colons:

There are cases where the the interpreter will automatically insert semi-colons as needed. You won't see them in the script source, but the interpreter knows they should be there. You should not rely on the interpreter doing your work for you. For example, semi-colons are never added inside for statement headers. Here are some instances of how the browser deals with automatic semi-colon insertion:

Warnings:

See also:Free-format language, Lexical convention, Line terminator, Semi-colon (;)

Cross-references:

ECMA 262 edition 2 - section - 7.8

ECMA 262 edition 3 - section - 7.9

O'Reilly JavaScript Definitive Guide - page - 28

Wrox Instant JavaScript - page - 17