Lexical convention (Definition)

ECMAScript defined certain lexical conventions.


ECMAScript edition - 2

According to the ECMAScript standard, a compliant interpreter should follow a certain logical process when converting the source text of a script into an executable form. The standard defines a set of logical entities, which can be combined to make a program. This abstract definition is broad enough that all JavaScript interpreters can be considered to be ECMAScript compliant on this issue.

A script is composed of an unordered collection of the following kinds of entities:

Whitespace is used to improve the readability of the script and to separate tokens from one another, where they could be misinterpreted if they were concatenated together.

Line terminators are used to improve the readability of the source text and to separate tokens. However, unlike whitespace, line terminators can affect the behavior of the script when placed in certain places. In general, a line terminator can occur between any two tokens but cannot appear in a token or inside a string literal. Line terminators in string literals must be escaped if they are required as part of the string. Line terminators also affect the automatic semicolon insertion process.

Comments can be contained completely on a single line or can span multiple lines.

A single line comment must finish at the end of the line and cannot contain a line terminator. You can place multiple single line comments one after another if required, each one separated by a line terminator.

Multiple line comments are replaced by a single line terminator during parsing. It doesn't matter how many line terminators they actually contain. This means that a multiple line comment behaves syntactically as if it were a line terminator.

Tokens are the actual components that your executable script is built from. They may be reserved words, identifiers, punctuator symbols or literals.

See also:Automatic semicolon insertion, Comment, Comment (// and /* ... */), Escape sequence (\), Line terminator, Multi-line comment, Script Source Text, Token, Whitespace


ECMA 262 edition 2 - section - 7

ECMA 262 edition 3 - section - 7

O'Reilly JavaScript Definitive Guide - page - 27

O'Reilly JavaScript Definitive Guide - page - 9-201