12.8 Literals
12.8.1 Null Literals
Syntax
12.8.2 Boolean Literals
Syntax
12.8.3 Numeric Literals
Syntax
The
For example: 3in
is an error and not the two input elements 3
and in
.
A conforming implementation, when processing
12.8.3.1 Static Semantics: MV
A numeric literal stands for a value of the Number type or the BigInt type.
-
The MV of
is the MV ofNumericLiteral :: DecimalLiteral DecimalLiteral . -
The MV of
is the MV ofNonDecimalIntegerLiteral :: BinaryIntegerLiteral BinaryIntegerLiteral . -
The MV of
is the MV ofNonDecimalIntegerLiteral :: OctalIntegerLiteral OctalIntegerLiteral . -
The MV of
is the MV ofNonDecimalIntegerLiteral :: HexIntegerLiteral HexIntegerLiteral . -
The MV of
is the MV ofDecimalLiteral :: DecimalIntegerLiteral . DecimalIntegerLiteral . -
The MV of
is the MV ofDecimalLiteral :: DecimalIntegerLiteral . DecimalDigits DecimalIntegerLiteral plus (the MV ofDecimalDigits × 10-n), where n is the number of code points inDecimalDigits , excluding all occurrences ofNumericLiteralSeparator . -
The MV of
is the MV ofDecimalLiteral :: DecimalIntegerLiteral . ExponentPart DecimalIntegerLiteral × 10e, where e is the MV ofExponentPart . -
The MV of
is (the MV ofDecimalLiteral :: DecimalIntegerLiteral . DecimalDigits ExponentPart DecimalIntegerLiteral plus (the MV ofDecimalDigits × 10-n)) × 10e, where n is the number of code points inDecimalDigits , excluding all occurrences ofNumericLiteralSeparator and e is the MV ofExponentPart . -
The MV of
is the MV ofDecimalLiteral :: . DecimalDigits DecimalDigits × 10-n, where n is the number of code points inDecimalDigits , excluding all occurrences ofNumericLiteralSeparator . -
The MV of
is the MV ofDecimalLiteral :: . DecimalDigits ExponentPart DecimalDigits × 10e - n, where n is the number of code points inDecimalDigits , excluding all occurrences ofNumericLiteralSeparator , and e is the MV ofExponentPart . -
The MV of
is the MV ofDecimalLiteral :: DecimalIntegerLiteral DecimalIntegerLiteral . -
The MV of
is the MV ofDecimalLiteral :: DecimalIntegerLiteral ExponentPart DecimalIntegerLiteral × 10e, where e is the MV ofExponentPart . -
The MV of
is 0.DecimalIntegerLiteral :: 0 -
The MV of
is the MV ofDecimalIntegerLiteral :: NonZeroDigit NonZeroDigit . -
The MV of
is (the MV ofDecimalIntegerLiteral :: NonZeroDigit NumericLiteralSeparator opt DecimalDigits NonZeroDigit × 10n) plus the MV ofDecimalDigits , where n is the number of code points inDecimalDigits , excluding all occurrences ofNumericLiteralSeparator . -
The MV of
is the MV ofDecimalDigits :: DecimalDigit DecimalDigit . -
The MV of
is (the MV ofDecimalDigits :: DecimalDigits DecimalDigit DecimalDigits × 10) plus the MV ofDecimalDigit . -
The MV of
is (the MV ofDecimalDigits :: DecimalDigits NumericLiteralSeparator DecimalDigit DecimalDigits × 10) plus the MV ofDecimalDigit . -
The MV of
is the MV ofExponentPart :: ExponentIndicator SignedInteger SignedInteger . -
The MV of
is the MV ofSignedInteger :: DecimalDigits DecimalDigits . -
The MV of
is the MV ofSignedInteger :: + DecimalDigits DecimalDigits . -
The MV of
is the negative of the MV ofSignedInteger :: - DecimalDigits DecimalDigits . -
The MV of
or ofDecimalDigit :: 0 or ofHexDigit :: 0 or ofOctalDigit :: 0 is 0.BinaryDigit :: 0 -
The MV of
or ofDecimalDigit :: 1 or ofNonZeroDigit :: 1 or ofHexDigit :: 1 or ofOctalDigit :: 1 is 1.BinaryDigit :: 1 -
The MV of
or ofDecimalDigit :: 2 or ofNonZeroDigit :: 2 or ofHexDigit :: 2 is 2.OctalDigit :: 2 -
The MV of
or ofDecimalDigit :: 3 or ofNonZeroDigit :: 3 or ofHexDigit :: 3 is 3.OctalDigit :: 3 -
The MV of
or ofDecimalDigit :: 4 or ofNonZeroDigit :: 4 or ofHexDigit :: 4 is 4.OctalDigit :: 4 -
The MV of
or ofDecimalDigit :: 5 or ofNonZeroDigit :: 5 or ofHexDigit :: 5 is 5.OctalDigit :: 5 -
The MV of
or ofDecimalDigit :: 6 or ofNonZeroDigit :: 6 or ofHexDigit :: 6 is 6.OctalDigit :: 6 -
The MV of
or ofDecimalDigit :: 7 or ofNonZeroDigit :: 7 or ofHexDigit :: 7 is 7.OctalDigit :: 7 -
The MV of
or ofDecimalDigit :: 8 or ofNonZeroDigit :: 8 is 8.HexDigit :: 8 -
The MV of
or ofDecimalDigit :: 9 or ofNonZeroDigit :: 9 is 9.HexDigit :: 9 -
The MV of
or ofHexDigit :: a is 10.HexDigit :: A -
The MV of
or ofHexDigit :: b is 11.HexDigit :: B -
The MV of
or ofHexDigit :: c is 12.HexDigit :: C -
The MV of
or ofHexDigit :: d is 13.HexDigit :: D -
The MV of
or ofHexDigit :: e is 14.HexDigit :: E -
The MV of
or ofHexDigit :: f is 15.HexDigit :: F -
The MV of
is the MV ofBinaryIntegerLiteral :: 0b BinaryDigits BinaryDigits . -
The MV of
is the MV ofBinaryIntegerLiteral :: 0B BinaryDigits BinaryDigits . -
The MV of
is the MV ofBinaryDigits :: BinaryDigit BinaryDigit . -
The MV of
is (the MV ofBinaryDigits :: BinaryDigits BinaryDigit BinaryDigits × 2) plus the MV ofBinaryDigit . -
The MV of
is (the MV ofBinaryDigits :: BinaryDigits NumericLiteralSeparator BinaryDigit BinaryDigits × 2) plus the MV ofBinaryDigit . -
The MV of
is the MV ofOctalIntegerLiteral :: 0o OctalDigits OctalDigits . -
The MV of
is the MV ofOctalIntegerLiteral :: 0O OctalDigits OctalDigits . -
The MV of
is the MV ofOctalDigits :: OctalDigit OctalDigit . -
The MV of
is (the MV ofOctalDigits :: OctalDigits OctalDigit OctalDigits × 8) plus the MV ofOctalDigit . -
The MV of
is (the MV ofOctalDigits :: OctalDigits NumericLiteralSeparator OctalDigit OctalDigits × 8) plus the MV ofOctalDigit . -
The MV of
is the MV ofHexIntegerLiteral :: 0x HexDigits HexDigits . -
The MV of
is the MV ofHexIntegerLiteral :: 0X HexDigits HexDigits . -
The MV of
is the MV ofHexDigits :: HexDigit HexDigit . -
The MV of
is (the MV ofHexDigits :: HexDigits HexDigit HexDigits × 16) plus the MV ofHexDigit . -
The MV of
is (the MV ofHexDigits :: HexDigits NumericLiteralSeparator HexDigit HexDigits × 16) plus the MV ofHexDigit .
12.8.3.2 Static Semantics: NumericValue
- Return the
Number value that results from rounding the MV ofDecimalLiteral as described below.
- Return the
Number value that results from rounding the MV ofNonDecimalIntegerLiteral as described below.
Once the exact MV for a numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is 0
digit or the 0
digit and then incrementing the literal at the 20th significant digit position. A digit is significant if it is not part of an
-
it is not
0
; or -
there is a non-zero digit to its left and there is a non-zero digit, not in the
ExponentPart , to its right.
- Return the BigInt value that represents the MV of
NonDecimalIntegerLiteral .
- Return
0 ℤ.
- Return the BigInt value that represents the MV of
NonZeroDigit .
- Let n be the number of code points in
DecimalDigits , excluding all occurrences ofNumericLiteralSeparator . - Let mv be (the MV of
NonZeroDigit × 10) plus the MV ofDecimalDigits . - Return
ℤ (mv).
12.8.4 String Literals
A string literal is 0 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), and U+000A (LINE FEED). Any code points may appear in the form of an escape sequence. String literals evaluate to ECMAScript String values. When generating these String values Unicode code points are UTF-16 encoded as defined in
Syntax
A conforming implementation, when processing
The definition of the nonterminal
<LF> and <CR> cannot appear in a string literal, except as part of a \n
or \u000A
.
12.8.4.1 Static Semantics: SV
A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of String values contributed by the various parts of the string literal. As part of this process, some Unicode code points within the string literal are interpreted as having a
-
The SV of
is the empty String.StringLiteral :: " " -
The SV of
is the empty String.StringLiteral :: ' ' -
The SV of
is theDoubleStringCharacters :: DoubleStringCharacter DoubleStringCharacters string-concatenation of the SV ofDoubleStringCharacter and the SV ofDoubleStringCharacters . -
The SV of
is theSingleStringCharacters :: SingleStringCharacter SingleStringCharacters string-concatenation of the SV ofSingleStringCharacter and the SV ofSingleStringCharacters . -
The SV of
is the result of performingDoubleStringCharacter :: SourceCharacter but not one of " or\ orLineTerminator UTF16EncodeCodePoint on the code point value ofSourceCharacter . -
The SV of
is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).DoubleStringCharacter :: <LS> -
The SV of
is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).DoubleStringCharacter :: <PS> -
The SV of
is the empty String.DoubleStringCharacter :: LineContinuation -
The SV of
is the result of performingSingleStringCharacter :: SourceCharacter but not one of ' or\ orLineTerminator UTF16EncodeCodePoint on the code point value ofSourceCharacter . -
The SV of
is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).SingleStringCharacter :: <LS> -
The SV of
is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).SingleStringCharacter :: <PS> -
The SV of
is the empty String.SingleStringCharacter :: LineContinuation -
The SV of
is the String value consisting of the code unit 0x0000 (NULL).EscapeSequence :: 0 -
The SV of
is the String value consisting of the code unit whose value is determined by theCharacterEscapeSequence :: SingleEscapeCharacter SingleEscapeCharacter according toTable 36 .
Escape Sequence | Code Unit Value | Unicode Character Name | Symbol |
---|---|---|---|
\b
|
0x0008
|
BACKSPACE | <BS> |
\t
|
0x0009
|
CHARACTER TABULATION | <HT> |
\n
|
0x000A
|
LINE FEED (LF) | <LF> |
\v
|
0x000B
|
LINE TABULATION | <VT> |
\f
|
0x000C
|
FORM FEED (FF) | <FF> |
\r
|
0x000D
|
CARRIAGE RETURN (CR) | <CR> |
\"
|
0x0022
|
QUOTATION MARK |
"
|
\'
|
0x0027
|
APOSTROPHE |
'
|
\\
|
0x005C
|
REVERSE SOLIDUS |
\
|
-
The SV of
is the result of performingNonEscapeCharacter :: SourceCharacter but not one of EscapeCharacter orLineTerminator UTF16EncodeCodePoint on the code point value ofSourceCharacter . -
The SV of
is the String value consisting of the code unit whose value is the MV ofHexEscapeSequence :: x HexDigit HexDigit HexEscapeSequence . -
The SV of
is the String value consisting of the code unit whose value is the MV ofHex4Digits :: HexDigit HexDigit HexDigit HexDigit Hex4Digits . -
The SV of
is the result of performingUnicodeEscapeSequence :: u{ CodePoint } UTF16EncodeCodePoint on the MV ofCodePoint .
12.8.4.2 Static Semantics: MV
-
The MV of
is (16 times the MV of the firstHexEscapeSequence :: x HexDigit HexDigit HexDigit ) plus the MV of the secondHexDigit . -
The MV of
is (0x1000 × the MV of the firstHex4Digits :: HexDigit HexDigit HexDigit HexDigit HexDigit ) plus (0x100 × the MV of the secondHexDigit ) plus (0x10 × the MV of the thirdHexDigit ) plus the MV of the fourthHexDigit .
12.8.5 Regular Expression Literals
A regular expression literal is an input element that is converted to a RegExp object (see ===
to each other even if the two literals' contents are identical. A RegExp object may also be created at runtime by new RegExp
or calling the RegExp
The productions below describe the syntax for a regular expression literal and are used by the input element scanner to find the end of the regular expression literal. The source text comprising the
An implementation may extend the ECMAScript Regular Expression grammar defined in
Syntax
Regular expression literals may not be empty; instead of representing an empty regular expression literal, the code unit sequence //
starts a single-line comment. To specify an empty regular expression, use: /(?:)/
.
12.8.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IdentifierPart contains a Unicode escape sequence.
12.8.5.2 Static Semantics: BodyText
- Return the source text that was recognized as
RegularExpressionBody .
12.8.5.3 Static Semantics: FlagText
- Return the source text that was recognized as
RegularExpressionFlags .
12.8.6 Template Literal Lexical Components
Syntax
A conforming implementation must not use the extended definition of
12.8.6.1 Static Semantics: TV and TRV
A template literal component is interpreted as a sequence of Unicode code points. The Template Value (TV) of a literal component is described in terms of String values (
-
The TV and TRV of
is the empty String.NoSubstitutionTemplate :: ` ` -
The TV and TRV of
is the empty String.TemplateHead :: ` ${ -
The TV and TRV of
is the empty String.TemplateMiddle :: } ${ -
The TV and TRV of
is the empty String.TemplateTail :: } ` -
The TV of
isTemplateCharacters :: TemplateCharacter TemplateCharacters undefined if either the TV ofTemplateCharacter isundefined or the TV ofTemplateCharacters isundefined . Otherwise, it is thestring-concatenation of the TV ofTemplateCharacter and the TV ofTemplateCharacters . -
The TV of
is the result of performingTemplateCharacter :: SourceCharacter but not one of ` or\ or$ orLineTerminator UTF16EncodeCodePoint on the code point value ofSourceCharacter . -
The TV of
is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).TemplateCharacter :: $ -
The TV of
is theTemplateCharacter :: \ EscapeSequence SV ofEscapeSequence . -
The TV of
isTemplateCharacter :: \ NotEscapeSequence undefined . -
The TV of
is the TRV ofTemplateCharacter :: LineTerminatorSequence LineTerminatorSequence . -
The TV of
is the empty String.LineContinuation :: \ LineTerminatorSequence -
The TRV of
is theTemplateCharacters :: TemplateCharacter TemplateCharacters string-concatenation of the TRV ofTemplateCharacter and the TRV ofTemplateCharacters . -
The TRV of
is the result of performingTemplateCharacter :: SourceCharacter but not one of ` or\ or$ orLineTerminator UTF16EncodeCodePoint on the code point value ofSourceCharacter . -
The TRV of
is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).TemplateCharacter :: $ -
The TRV of
is theTemplateCharacter :: \ EscapeSequence string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV ofEscapeSequence . -
The TRV of
is theTemplateCharacter :: \ NotEscapeSequence string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV ofNotEscapeSequence . -
The TRV of
is the String value consisting of the code unit 0x0030 (DIGIT ZERO).EscapeSequence :: 0 -
The TRV of
is theNotEscapeSequence :: 0 DecimalDigit string-concatenation of the code unit 0x0030 (DIGIT ZERO) and the TRV ofDecimalDigit . -
The TRV of
is the String value consisting of the code unit 0x0078 (LATIN SMALL LETTER X).NotEscapeSequence :: x [lookahead ∉ HexDigit ] -
The TRV of
is theNotEscapeSequence :: x HexDigit [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0078 (LATIN SMALL LETTER X) and the TRV ofHexDigit . -
The TRV of
is the String value consisting of the code unit 0x0075 (LATIN SMALL LETTER U).NotEscapeSequence :: u [lookahead ∉ HexDigit ][lookahead ≠ { ] -
The TRV of
is theNotEscapeSequence :: u HexDigit [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the TRV ofHexDigit . -
The TRV of
is theNotEscapeSequence :: u HexDigit HexDigit [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the TRV of the firstHexDigit , and the TRV of the secondHexDigit . -
The TRV of
is theNotEscapeSequence :: u HexDigit HexDigit HexDigit [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the TRV of the firstHexDigit , the TRV of the secondHexDigit , and the TRV of the thirdHexDigit . -
The TRV of
is theNotEscapeSequence :: u { [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the code unit 0x007B (LEFT CURLY BRACKET). -
The TRV of
is theNotEscapeSequence :: u { NotCodePoint [lookahead ∉ HexDigit ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), and the TRV ofNotCodePoint . -
The TRV of
is theNotEscapeSequence :: u { CodePoint [lookahead ∉ HexDigit ][lookahead ≠ } ]string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), and the TRV ofCodePoint . -
The TRV of
is the result of performingDecimalDigit :: one of 0 1 2 3 4 5 6 7 8 9 UTF16EncodeCodePoint on the single code point matched by this production. -
The TRV of
is theCharacterEscapeSequence :: NonEscapeCharacter SV ofNonEscapeCharacter . -
The TRV of
is the result of performingSingleEscapeCharacter :: one of ' " \ b f n r t v UTF16EncodeCodePoint on the single code point matched by this production. -
The TRV of
is theHexEscapeSequence :: x HexDigit HexDigit string-concatenation of the code unit 0x0078 (LATIN SMALL LETTER X), the TRV of the firstHexDigit , and the TRV of the secondHexDigit . -
The TRV of
is theUnicodeEscapeSequence :: u Hex4Digits string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U) and the TRV ofHex4Digits . -
The TRV of
is theUnicodeEscapeSequence :: u{ CodePoint } string-concatenation of the code unit 0x0075 (LATIN SMALL LETTER U), the code unit 0x007B (LEFT CURLY BRACKET), the TRV ofCodePoint , and the code unit 0x007D (RIGHT CURLY BRACKET). -
The TRV of
is theHex4Digits :: HexDigit HexDigit HexDigit HexDigit string-concatenation of the TRV of the firstHexDigit , the TRV of the secondHexDigit , the TRV of the thirdHexDigit , and the TRV of the fourthHexDigit . -
The TRV of
is theHexDigits :: HexDigits HexDigit string-concatenation of the TRV ofHexDigits and the TRV ofHexDigit . -
The TRV of
is the result of performingHexDigit :: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F UTF16EncodeCodePoint on the single code point matched by this production. -
The TRV of
is theLineContinuation :: \ LineTerminatorSequence string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV ofLineTerminatorSequence . -
The TRV of
is the String value consisting of the code unit 0x000A (LINE FEED).LineTerminatorSequence :: <LF> -
The TRV of
is the String value consisting of the code unit 0x000A (LINE FEED).LineTerminatorSequence :: <CR> -
The TRV of
is the String value consisting of the code unit 0x2028 (LINE SEPARATOR).LineTerminatorSequence :: <LS> -
The TRV of
is the String value consisting of the code unit 0x2029 (PARAGRAPH SEPARATOR).LineTerminatorSequence :: <PS> -
The TRV of
is the String value consisting of the code unit 0x000A (LINE FEED).LineTerminatorSequence :: <CR> <LF>
TV excludes the code units of