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.
Line terminators occurring during a single line comment delimited by a pair of slash characters (//) are considered to be the end of the comment, and any remaining comment text be interpreted as if it were executable code.
Line terminators occurring during a multiple line comment block (/* ... */) will be discarded and the entire comment block will be replaced with a single line terminator.
The following characters are considered to be line terminators in ECMAScript conformant JavaScript interpreters:
Escape Sequence | Unicode Value | Name | Symbol |
\n | \u000A | Line Feed | <LF> |
\r | \u000D | Carriage Return | <CR> |
- | \2028 | Line separator | <LS> |
- | \2029 | Paragraph separator | <PS> |
The terms Line Terminator and Newline can for most purposes be used interchangeably. Newline is preferred when referring to a \n escape sequence since it more clearly suggests the meaning of the escape.
ECMA edition 3 adds the Unicode line separator and paragraph separator code points to the list of valid line terminators.
ECMA 262 edition 2 - section - 7.2
ECMA 262 edition 2 - section - 7.8
ECMA 262 edition 3 - section - 7.3
Prev | Home | Next |
Line | Up | LINK object |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |