Whitespace (Definition)

White space is used to separate tokens from one another.

Availability:

ECMAScript edition - 2

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.

Whitespace characters are insignificant to the script execution apart from how they may affect the interpretation of tokens. The placement of white space can affect the way an expression is evaluated. For example:

   a = 10000;

Will assign the value 10000 to the variable a, whereas:

   a = 10 000;

May assign the value 10 to variable a but will likely generate a syntax error unless the interpreter is especially forgiving. Strictly speaking the interpreter should reject this:

   a = c ++;

Is also incorrect since the postfix operator is dissociated from the variable it operates on by the whitespace in between.

Actually, there are remarkably few places that whitespace cannot be introduced.

The following characters are considered to be whitespace in ECMAScript conforming JavaScript interpreters:

Escape SequenceUnicode ValueNameSymbol
\t\u0009Tab<TAB>
-\u000BVertical Tab<VT>
\f\u000CForm Feed<FF>
-\u0020Space<SP>
-\00A0No-break space<NBSP>
-Other category "Zs"Other Unicode space characters<USP>

ECMA edition 3 adds a couple of new whitespace character definitions. One is the non-breaking space and the other refers generally to Unicode spacing characters.

See also:Lexical convention, Lexical element

Cross-references:

ECMA 262 edition 2 - section - 7.1

ECMA 262 edition 3 - section - 7.2

O'Reilly JavaScript Definitive Guide - page - 28