12.9 Literals
12.9.1 Null Literals
Syntax
12.9.2 Boolean Literals
Syntax
12.9.3 Numeric Literals
Syntax
The
For example: 3in
is an error and not the two input elements 3
and in
.
12.9.3.1 Static Semantics: Early Errors
- It is a Syntax Error if the
source text matched by this production isstrict mode code .
12.9.3.2 Static Semantics: MV
A numeric literal stands for a value of the
-
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 ExponentPart DecimalIntegerLiteral × 10e, where e is the MV ofExponentPart . -
The MV of
is 0.DecimalIntegerLiteral :: 0 -
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 :: 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 negative of the MV ofSignedInteger :: - DecimalDigits DecimalDigits . -
The MV of
or ofDecimalDigit :: 0 or ofHexDigit :: 0 or ofOctalDigit :: 0 or ofLegacyOctalEscapeSequence :: 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 or ofNonOctalDigit :: 8 is 8.HexDigit :: 8 -
The MV of
or ofDecimalDigit :: 9 or ofNonZeroDigit :: 9 or ofNonOctalDigit :: 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 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 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 ofLegacyOctalIntegerLiteral :: LegacyOctalIntegerLiteral OctalDigit LegacyOctalIntegerLiteral times 8) plus the MV ofOctalDigit . -
The MV of
is (the MV ofNonOctalDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral NonOctalDigit LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV ofNonOctalDigit . -
The MV of
is (the MV ofNonOctalDecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral DecimalDigit NonOctalDecimalIntegerLiteral times 10) plus the MV ofDecimalDigit . -
The MV of
is (the MV ofLegacyOctalLikeDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral OctalDigit LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV ofOctalDigit . -
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.9.3.3 Static Semantics: NumericValue
The
- Return
RoundMVResult (MV ofDecimalLiteral ).
- Return
𝔽 (MV ofNonDecimalIntegerLiteral ).
- Return
𝔽 (MV ofLegacyOctalIntegerLiteral ).
- Return the
BigInt value for the MV ofNonDecimalIntegerLiteral .
- Return
0 ℤ.
- Return the
BigInt value for the MV ofNonZeroDigit .
- Let n be the number of code points in
DecimalDigits , excluding all occurrences ofNumericLiteralSeparator . - Let mv be (the MV of
NonZeroDigit × 10n) plus the MV ofDecimalDigits . - Return
ℤ (mv).
12.9.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
The definition of the nonterminal
<LF> and <CR> cannot appear in a string literal, except as part of a \n
or \u000A
.
12.9.4.1 Static Semantics: Early Errors
- It is a Syntax Error if the
source text matched by this production isstrict mode code .
It is possible for string literals to precede a
function invalid() { "\7"; "use strict"; }
12.9.4.2 Static Semantics: SV
The
A string literal stands for a value of the
-
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 matched bySourceCharacter . -
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 matched bySourceCharacter . -
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 numeric value is determined by theCharacterEscapeSequence :: SingleEscapeCharacter SingleEscapeCharacter according toTable 38 .
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 matched bySourceCharacter . -
The SV of
is the String value consisting of the code unit whose numeric value is the MV ofEscapeSequence :: LegacyOctalEscapeSequence LegacyOctalEscapeSequence . -
The SV of
is the String value consisting of the code unit 0x0038 (DIGIT EIGHT).NonOctalDecimalEscapeSequence :: 8 -
The SV of
is the String value consisting of the code unit 0x0039 (DIGIT NINE).NonOctalDecimalEscapeSequence :: 9 -
The SV of
is the String value consisting of the code unit whose numeric value is the MV ofHexEscapeSequence :: x HexDigit HexDigit HexEscapeSequence . -
The SV of
is the String value consisting of the code unit whose numeric 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 . -
The SV of
is the String value consisting of the code unit 0x0000 (NULL).TemplateEscapeSequence :: 0
12.9.4.3 Static Semantics: MV
-
The MV of
is (8 times the MV ofLegacyOctalEscapeSequence :: ZeroToThree OctalDigit ZeroToThree ) plus the MV ofOctalDigit . -
The MV of
is (8 times the MV ofLegacyOctalEscapeSequence :: FourToSeven OctalDigit FourToSeven ) plus the MV ofOctalDigit . -
The MV of
is (64 (that is, 82) times the MV ofLegacyOctalEscapeSequence :: ZeroToThree OctalDigit OctalDigit ZeroToThree ) plus (8 times the MV of the firstOctalDigit ) plus the MV of the secondOctalDigit . -
The MV of
is 0.ZeroToThree :: 0 -
The MV of
is 1.ZeroToThree :: 1 -
The MV of
is 2.ZeroToThree :: 2 -
The MV of
is 3.ZeroToThree :: 3 -
The MV of
is 4.FourToSeven :: 4 -
The MV of
is 5.FourToSeven :: 5 -
The MV of
is 6.FourToSeven :: 6 -
The MV of
is 7.FourToSeven :: 7 -
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.9.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.9.5.1 Static Semantics: BodyText
The
- Return the source text that was recognized as
RegularExpressionBody .
12.9.5.2 Static Semantics: FlagText
The
- Return the source text that was recognized as
RegularExpressionFlags .
12.9.6 Template Literal Lexical Components
Syntax
12.9.6.1 Static Semantics: TV
The
-
The TV of
is the empty String.NoSubstitutionTemplate :: ` ` -
The TV of
is the empty String.TemplateHead :: ` ${ -
The TV of
is the empty String.TemplateMiddle :: } ${ -
The TV of
is the empty String.TemplateTail :: } ` -
The TV of
isTemplateCharacters :: TemplateCharacter TemplateCharacters undefined if 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 matched bySourceCharacter . -
The TV of
is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).TemplateCharacter :: $ -
The TV of
is theTemplateCharacter :: \ TemplateEscapeSequence SV ofTemplateEscapeSequence . -
The TV of
isTemplateCharacter :: \ NotEscapeSequence undefined . -
The TV of
is theTemplateCharacter :: LineTerminatorSequence TRV ofLineTerminatorSequence . -
The TV of
is the empty String.LineContinuation :: \ LineTerminatorSequence
12.9.6.2 Static Semantics: TRV
The
-
The TRV of
is the empty String.NoSubstitutionTemplate :: ` ` -
The TRV of
is the empty String.TemplateHead :: ` ${ -
The TRV of
is the empty String.TemplateMiddle :: } ${ -
The TRV of
is the empty String.TemplateTail :: } ` -
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 matched bySourceCharacter . -
The TRV of
is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).TemplateCharacter :: $ -
The TRV of
is theTemplateCharacter :: \ TemplateEscapeSequence string-concatenation of the code unit 0x005C (REVERSE SOLIDUS) and the TRV ofTemplateEscapeSequence . -
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).TemplateEscapeSequence :: 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>