The below excerpts refer to ECMAScript 2017.
10.1 Source Text, Syntax
Escape sequences, like \u000A
, will not be interpreted as line terminators (i.e. new lines):
In string literals, regular expression literals, template literals and identifiers, any Unicode code point may also be expressed using Unicode escape sequences that explicitly express a code point's numeric value. Within a comment, such an escape sequence is effectively ignored as part of the comment.
ECMAScript differs from the Java programming language in the behaviour of Unicode escape sequences.
If the Unicode escape sequence \u000A occurs within a string literal in a Java program, it is interpreted as a line terminator, which is not allowed within a string literal.
A Unicode escape sequence occurring within a string literal in an ECMAScript program, always contributes to the literal and is never interpreted as a line terminator or as a code point that might terminate the string literal.
11.8.4 String Literals
Code points may appear as escape sequences in string literals, except reverse solidus (\
).
A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. All code points may appear literally in a string literal except for the closing quote code points, U+005C (REVERSE SOLIDUS), U+000D (CARRIAGE RETURN), U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR), and U+000A (LINE FEED). Any code points may appear in the form of an escape sequence.
Questions
- How can an escape sequence occur inside a string literal, if
\
is not allowed (11.8.4)? - 11.8.4. states that code points may be represented as escape sequences. 10.1 states that escape sequence
\u000A
inside a string literal is not interpreted as aline terminator
. These two seem contradictory. If it is not interpreted as a line break inside the string literal, then how is it interpreted (if at all)?