ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 24

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     22      23      24      25     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 24

 

 

NOTE 1

NOTE 2

Directive Prologue

 is the longest sequence of 

ExpressionStatement

s occurring as the initial 

StatementListItem

s or 

ModuleItem

s of a 

FunctionBody

, a 

ScriptBody

, or a 

ModuleBody

 and where each 

ExpressionStatement

 in the sequence

consists entirely of a 

StringLiteral

 token followed by a semicolon. The semicolon may appear explicitly or may be

inserted by automatic semicolon insertion (

12.9

). A 

Directive Prologue

 may be an empty sequence.

Use Strict Directive

 is an 

ExpressionStatement

 in a 

Directive Prologue

 whose 

StringLiteral

 is either of the exact code

point sequences 

"use strict"

"use strict"

 or 

'use strict'

'use strict'

. A 

Use Strict Directive

 may not contain an 

EscapeSequence

 or 

LineContinuation

.

Directive Prologue

 may contain more than one 

Use Strict Directive

. However, an implementation may issue a

warning if this occurs.

NOTE

An ECMAScript syntactic unit may be processed using either unrestricted or strict mode syntax and semantics (

4.3.2

).

Code is interpreted as 

strict mode code

 in the following situations:

Global code is strict mode code if it begins with a 

Directive Prologue

 that contains a 

Use Strict Directive

.

Module code is always strict mode code.
All parts of a 

ClassDeclaration

 or a 

ClassExpression

 are strict mode code.

Eval code is strict mode code if it begins with a 

Directive Prologue

 that contains a 

Use Strict Directive

 or if the

call to 

eval

eval

 is a 

direct eval

 that is contained in strict mode code.

Function code is strict mode code if the associated 

FunctionDeclaration

FunctionExpression

GeneratorDeclaration

GeneratorExpression

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

AsyncGeneratorExpression

MethodDefinition

ArrowFunction

, or 

AsyncArrowFunction

 is contained in strict mode

code or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a

Function code is generally provided as the bodies of Function Definitions (

15.2

), Arrow Function

Definitions (

15.3

), Method Definitions (

15.4

), Generator Function Definitions (

15.5

), Async

Function Definitions (

15.8

), Async Generator Function Definitions (

15.6

), and Async Arrow

Functions (

15.9

). Function code is also derived from the arguments to the Function 

constructor

(

20.2.1.1

), the GeneratorFunction 

constructor

 (

27.3.1.1

), and the AsyncFunction 

constructor

(

27.7.1.1

).

The practical effect of including the 

BindingIdentifier

 in function code is that the Early Errors for

strict mode code

 are applied to a 

BindingIdentifier

 that is the name of a function whose body

contains a "use strict" directive, even if the surrounding code is not 

strict mode code

.

The 

ExpressionStatement

s of a 

Directive Prologue

 are evaluated normally during evaluation of the

containing production. Implementations may define implementation specific meanings for 

ExpressionStatement

s which are not a 

Use Strict Directive

 and which occur in a 

Directive Prologue

.

If an appropriate notification mechanism exists, an implementation should issue a warning if it
encounters in a 

Directive Prologue

 an 

ExpressionStatement

 that is not a 

Use Strict Directive

 and

which does not have a meaning defined by the implementation.

11.2.1  Directive Prologues and the Use Strict Directive

11.2.2  Strict Mode Code

275

Directive Prologue

 that contains a 

Use Strict Directive

.

Function code that is supplied as the arguments to the built-in Function, Generator, AsyncFunction, and
AsyncGenerator constructors is strict mode code if the last argument is a String that when processed is a 

FunctionBody

 that begins with a 

Directive Prologue

 that contains a 

Use Strict Directive

.

ECMAScript code that is not strict mode code is called 

non-strict code

.

An ECMAScript implementation may support the evaluation of function exotic objects whose evaluative behaviour is
expressed in some 

host-defined

 form of executable code other than via ECMAScript code. Whether a 

function object

 is

an ECMAScript code function or a non-ECMAScript function is not semantically observable from the perspective of
an ECMAScript code function that calls or is called by such a non-ECMAScript function.

The source text of an ECMAScript 

Script

 or 

Module

 is first converted into a sequence of input elements, which are

tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the
longest possible sequence of code points as the next input element.

There are several situations where the identification of lexical input elements is sensitive to the syntactic grammar
context that is consuming the input elements. This requires multiple goal symbols for the lexical grammar. The 

InputElementRegExpOrTemplateTail

 goal is used in syntactic grammar contexts where a 

RegularExpressionLiteral

, a 

TemplateMiddle

, or a 

TemplateTail

 is permitted. The 

InputElementRegExp

 

goal symbol

 is used in all syntactic grammar

contexts where a 

RegularExpressionLiteral

 is permitted but neither a 

TemplateMiddle

, nor a 

TemplateTail

 is permitted. The

InputElementTemplateTail

 goal is used in all syntactic grammar contexts where a 

TemplateMiddle

 or a 

TemplateTail

 is

permitted but a 

RegularExpressionLiteral

 is not permitted. In all other contexts, 

InputElementDiv

 is used as the lexical

goal symbol

.

NOTE

InputElementDiv

 

::

The use of multiple lexical goals ensures that there are no lexical ambiguities that would affect
automatic semicolon insertion. For example, there are no syntactic grammar contexts where both
a leading division or division-assignment, and a leading 

RegularExpressionLiteral

 are permitted.

This is not affected by semicolon insertion (see 

12.9

); in examples such as the following:

where the first non-whitespace, non-comment code point after a 

LineTerminator

 is U+002F

(SOLIDUS) and the syntactic context allows division or division-assignment, no semicolon is
inserted at the 

LineTerminator

. That is, the above example is interpreted in the same way as:

a = b
/hi/g.exec(c).map(d);

a = b / hi / g.exec(c).map(d);

11.2.3  Non-ECMAScript Functions

12  ECMAScript Language: Lexical Grammar

Syntax

276

WhiteSpace
LineTerminator
Comment
CommonToken
DivPunctuator
RightBracePunctuator

InputElementRegExp

 

::

WhiteSpace
LineTerminator
Comment
CommonToken
RightBracePunctuator
RegularExpressionLiteral

InputElementRegExpOrTemplateTail

 

::

WhiteSpace
LineTerminator
Comment
CommonToken
RegularExpressionLiteral
TemplateSubstitutionTail

InputElementTemplateTail

 

::

WhiteSpace
LineTerminator
Comment
CommonToken
DivPunctuator
TemplateSubstitutionTail

The Unicode format-control characters (i.e., the characters in category “Cf” in the Unicode Character Database such as
LEFT-TO-RIGHT MARK or RIGHT-TO-LEFT MARK) are control codes used to control the formatting of a range of
text in the absence of higher-level protocols for this (such as mark-up languages).

It is useful to allow format-control characters in source text to facilitate editing and display. All format control
characters may be used within comments, and within string literals, template literals, and regular expression literals.

U+200C (ZERO WIDTH NON-JOINER) and U+200D (ZERO WIDTH JOINER) are format-control characters that are
used to make necessary distinctions when forming words or phrases in certain languages. In ECMAScript source text
these code points may also be used in an 

IdentifierName

 after the first character.

U+FEFF (ZERO WIDTH NO-BREAK SPACE) is a format-control character used primarily at the start of a text to mark
it as Unicode and to allow detection of the text's encoding and byte order. <ZWNBSP> characters intended for this

12.1  Unicode Format-Control Characters

277

purpose can sometimes also appear after the start of a text, for example as a result of concatenating files. In
ECMAScript source text <ZWNBSP> code points are treated as white space characters (see 

12.2

).

The special treatment of certain format-control characters outside of comments, string literals, and regular expression
literals is summarized in 

Table 33

.

Table 33: Format-Control Code Point Usage

Code Point

Name

Abbreviation

Usage

U+200C

U+200C

ZERO WIDTH NON-JOINER

<ZWNJ>

IdentifierPart

U+200D

U+200D

ZERO WIDTH JOINER

<ZWJ>

IdentifierPart

U+FEFF

U+FEFF

ZERO WIDTH NO-BREAK SPACE <ZWNBSP>

WhiteSpace

White space code points are used to improve source text readability and to separate tokens (indivisible lexical units)
from each other, but are otherwise insignificant. White space code points may occur between any two tokens and at
the start or end of input. White space code points may occur within a 

StringLiteral

, a 

RegularExpressionLiteral

, a 

Template

, or a 

TemplateSubstitutionTail

 where they are considered significant code points forming part of a literal value.

They may also occur within a 

Comment

, but cannot appear within any other kind of token.

The ECMAScript white space code points are listed in 

Table 34

.

Table 34: White Space Code Points

Code Point

Name

Abbreviation

U+0009

U+0009

CHARACTER TABULATION

<TAB>

U+000B

U+000B

LINE TABULATION

<VT>

U+000C

U+000C

FORM FEED (FF)

<FF>

U+0020

U+0020

SPACE

<SP>

U+00A0

U+00A0

NO-BREAK SPACE

<NBSP>

U+FEFF

U+FEFF

ZERO WIDTH NO-BREAK SPACE

<ZWNBSP>

Other category “Zs” Any other Unicode “Space_Separator” code point <USP>

ECMAScript implementations must recognize as 

WhiteSpace

 code points listed in the “Space_Separator” (“Zs”)

category.

NOTE

Other than for the code points listed in 

Table 34

, ECMAScript 

WhiteSpace

 intentionally excludes

all code points that have the Unicode “White_Space” property but which are not classified in
category “Space_Separator” (“Zs”).

12.2  White Space

278

WhiteSpace

 

::

<TAB>

<VT>

<FF>

<SP>

<NBSP>

<ZWNBSP>

<USP>

Like white space code points, line terminator code points are used to improve source text readability and to separate
tokens (indivisible lexical units) from each other. However, unlike white space code points, line terminators have
some influence over the behaviour of the syntactic grammar. In general, line terminators may occur between any two
tokens, but there are a few places where they are forbidden by the syntactic grammar. Line terminators also affect the
process of automatic semicolon insertion (

12.9

). A line terminator cannot occur within any token except a 

StringLiteral

,

Template

, or 

TemplateSubstitutionTail

. <LF> and <CR> line terminators cannot occur within a 

StringLiteral

 token except

as part of a 

LineContinuation

.

A line terminator can occur within a 

MultiLineComment

 but cannot occur within a 

SingleLineComment

.

Line terminators are included in the set of white space code points that are matched by the 

\s

\s

 class in regular

expressions.

The ECMAScript line terminator code points are listed in 

Table 35

.

Table 35: Line Terminator Code Points

Code Point

Unicode Name

Abbreviation

U+000A

U+000A

LINE FEED (LF)

<LF>

U+000D

U+000D

CARRIAGE RETURN (CR)

<CR>

U+2028

U+2028

LINE SEPARATOR

<LS>

U+2029

U+2029

PARAGRAPH SEPARATOR <PS>

Only the Unicode code points in 

Table 35

 are treated as line terminators. Other new line or line breaking Unicode code

points are not treated as line terminators but are treated as white space if they meet the requirements listed in 

Table

34

. The sequence <CR><LF> is commonly used as a line terminator. It should be considered a single 

SourceCharacter

for the purpose of reporting line numbers.

LineTerminator

 

::

<LF>

Syntax

12.3  Line Terminators

Syntax

279

<CR>

<LS>

<PS>

LineTerminatorSequence

 

::

<LF>

<CR>

 [lookahead 

 

<LF>

]

<LS>

<PS>

<CR>

 

<LF>

Comments can be either single or multi-line. Multi-line comments cannot nest.

Because a single-line comment can contain any Unicode code point except a 

LineTerminator

 code point, and because of

the general rule that a token is always as long as possible, a single-line comment always consists of all code points
from the 

//

//

 marker to the end of the line. However, the 

LineTerminator

 at the end of the line is not considered to be

part of the single-line comment; it is recognized separately by the lexical grammar and becomes part of the stream of
input elements for the syntactic grammar. This point is very important, because it implies that the presence or absence
of single-line comments does not affect the process of automatic semicolon insertion (see 

12.9

).

Comments behave like white space and are discarded except that, if a 

MultiLineComment

 contains a line terminator

code point, then the entire comment is considered to be a 

LineTerminator

 for purposes of parsing by the syntactic

grammar.

Comment

 

::

MultiLineComment
SingleLineComment

MultiLineComment

 

::

/*

 

MultiLineCommentChars

opt

 

*/

MultiLineCommentChars

 

::

MultiLineNotAsteriskChar

 

MultiLineCommentChars

opt

*

 

PostAsteriskCommentChars

opt

PostAsteriskCommentChars

 

::

MultiLineNotForwardSlashOrAsteriskChar

 

MultiLineCommentChars

opt

*

 

PostAsteriskCommentChars

opt

MultiLineNotAsteriskChar

 

::

SourceCharacter

 but not 

*

MultiLineNotForwardSlashOrAsteriskChar

 

::

SourceCharacter

 but not one of 

/

 or 

*

12.4  Comments

Syntax

280

SingleLineComment

 

::

//

 

SingleLineCommentChars

opt

SingleLineCommentChars

 

::

SingleLineCommentChar

 

SingleLineCommentChars

opt

SingleLineCommentChar

 

::

SourceCharacter

 but not 

LineTerminator

A number of productions in this section are given alternative definitions in section 

B.1.3

CommonToken

 

::

IdentifierName
Punctuator
NumericLiteral
StringLiteral
Template

NOTE

IdentifierName

 and 

ReservedWord

 are tokens that are interpreted according to the Default Identifier Syntax given in

Unicode Standard Annex #31, Identifier and Pattern Syntax, with some small modifications. 

ReservedWord

 is an

enumerated subset of 

IdentifierName

. The syntactic grammar defines 

Identifier

 as an 

IdentifierName

 that is not a 

ReservedWord

. The Unicode identifier grammar is based on character properties specified by the Unicode Standard.

The Unicode code points in the specified categories in the latest version of the Unicode standard must be treated as in
those categories by all conforming ECMAScript implementations. ECMAScript implementations may recognize
identifier code points defined in later editions of the Unicode Standard.

NOTE 1

Unicode escape sequences are permitted in an 

IdentifierName

, where they contribute a single Unicode code point to the

IdentifierName

. The code point is expressed by the 

CodePoint

 of the 

UnicodeEscapeSequence

 (see 

12.8.4

). The 

\\

 preceding

the 

UnicodeEscapeSequence

 and the 

uu

 and 

{ }

{ }

 code units, if they appear, do not contribute code points to the 

IdentifierName

. A 

UnicodeEscapeSequence

 cannot be used to put a code point into an 

IdentifierName

 that would otherwise

be illegal. In other words, if a 

\\

 

UnicodeEscapeSequence

 sequence were replaced by the 

SourceCharacter

 it contributes,

The 

DivPunctuator

RegularExpressionLiteral

RightBracePunctuator

, and 

TemplateSubstitutionTail

productions derive additional tokens that are not included in the 

CommonToken

 production.

This standard specifies specific code point additions: U+0024 (DOLLAR SIGN) and U+005F
(LOW LINE) are permitted anywhere in an 

IdentifierName

, and the code points U+200C (ZERO

WIDTH NON-JOINER) and U+200D (ZERO WIDTH JOINER) are permitted anywhere after the
first code point of an 

IdentifierName

.

12.5  Tokens

Syntax

12.6  Names and Keywords

281

the result must still be a valid 

IdentifierName

 that has the exact same sequence of 

SourceCharacter

 elements as the

original 

IdentifierName

. All interpretations of 

IdentifierName

 within this specification are based upon their actual code

points regardless of whether or not an escape sequence was used to contribute any particular code point.

Two 

IdentifierName

s that are canonically equivalent according to the Unicode standard are 

not

 equal unless, after

replacement of each 

UnicodeEscapeSequence

, they are represented by the exact same sequence of code points.

IdentifierName

 

::

IdentifierStart
IdentifierName

 

IdentifierPart

IdentifierStart

 

::

UnicodeIDStart

$

_

\

 

UnicodeEscapeSequence

IdentifierPart

 

::

UnicodeIDContinue

$

\

 

UnicodeEscapeSequence

<ZWNJ>

<ZWJ>

UnicodeIDStart

 

::

any Unicode code point with the Unicode property “ID_Start”

UnicodeIDContinue

 

::

any Unicode code point with the Unicode property “ID_Continue”

The definitions of the nonterminal 

UnicodeEscapeSequence

 is given in 

12.8.4

.

NOTE 2

NOTE 3

IdentifierStart

 

::

 

\

 

UnicodeEscapeSequence

It is a Syntax Error if the 

SV

 of 

UnicodeEscapeSequence

 is none of 

"$"

, or 

"_"

, or ! 

UTF16EncodeCodePoint

(

cp

) for

some Unicode code point 

cp

 matched by the 

UnicodeIDStart

 lexical grammar production.

The nonterminal 

IdentifierPart

 derives 

__

 via 

UnicodeIDContinue

.

The sets of code points with Unicode properties “ID_Start” and “ID_Continue” include,
respectively, the code points with Unicode properties “Other_ID_Start” and
“Other_ID_Continue”.

Syntax

12.6.1  Identifier Names

12.6.1.1  Static Semantics: Early Errors

282

IdentifierPart

 

::

 

\

 

UnicodeEscapeSequence

It is a Syntax Error if the 

SV

 of 

UnicodeEscapeSequence

 is none of 

"$"

"_"

, ! 

UTF16EncodeCodePoint

(<ZWNJ>), !

UTF16EncodeCodePoint

(<ZWJ>), or ! 

UTF16EncodeCodePoint

(

cp

) for some Unicode code point 

cp

 that would

be matched by the 

UnicodeIDContinue

 lexical grammar production.

keyword

 is a token that matches 

IdentifierName

, but also has a syntactic use; that is, it appears literally, in a

fixed width

fixed width

 font, in some syntactic production. The keywords of ECMAScript include 

if

if

while

while

async

async

,

await

await

, and many others.

reserved word

 is an 

IdentifierName

 that cannot be used as an identifier. Many keywords are reserved words, but some

are not, and some are reserved only in certain contexts. 

if

if

 and 

while

while

 are reserved words. 

await

await

 is reserved only

inside async functions and modules. 

async

async

 is not reserved; it can be used as a variable name or statement label

without restriction.

This specification uses a combination of grammatical productions and 

early error

 rules to specify which names are

valid identifiers and which are reserved words. All tokens in the 

ReservedWord

 list below, except for 

await

await

 and

yield

yield

, are unconditionally reserved. Exceptions for 

await

await

 and 

yield

yield

 are specified in 

13.1

, using parameterized

syntactic productions. Lastly, several 

early error

 rules restrict the set of valid identifiers. See 

13.1.1

14.3.1.1

14.7.5.1

,

and 

15.7.1

. In summary, there are five categories of identifier names:

Those that are always allowed as identifiers, and are not keywords, such as 

Math

Math

window

window

toString

toString

, and

__

;

Those that are never allowed as identifiers, namely the 

ReservedWord

s listed below except 

await

await

 and 

yield

yield

;

Those that are contextually allowed as identifiers, namely 

await

await

 and 

yield

yield

;

Those that are contextually disallowed as identifiers, in 

strict mode code

let

let

static

static

implements

implements

,

interface

interface

package

package

private

private

protected

protected

, and 

public

public

;

Those that are always allowed as identifiers, but also appear as keywords within certain syntactic productions,
at places wher

Identifier

 is not allowed: 

as

as

async

async

from

from

get

get

of

of

set

set

, and 

target

target

.

The term 

conditional keyword

, or 

contextual keyword

, is sometimes used to refer to the keywords that fall in the last three

categories, and thus can be used as identifiers in some contexts and as keywords in others.

ReservedWord

 

::

 

one of

await

 

break

 

case

 

catch

 

class

 

const

 

continue

 

debugger

 

default

 

delete

 

do

 

else

 

enum

 

export

 

extends

 

false

 

finally

 

for

 

function

 

if

 

import

 

in

 

instanceof

 

new

 

null

 

return

 

super

 

switch

 

this

 

throw

 

true

 

try

 

typeof

 

var

 

void

 

while

 

with

 

yield

12.6.2  Keywords and Reserved Words

Syntax

283

NOTE 1

NOTE 2

NOTE 3

Punctuator

 

::

OptionalChainingPunctuator
OtherPunctuator

OptionalChainingPunctuator

 

::

?.

 [lookahead 

 

DecimalDigit

]

OtherPunctuator

 

::

 

one of

{

 

(

 

)

 

[

 

]

 

.

 

...

 

;

 

,

 

<

 

>

 

<=

 

>=

 

==

 

!=

 

===

 

!==

 

+

 

-

 

*

 

%

 

**

 

++

 

--

 

<<

 

>>

 

>>>

 

&

 

|

 

^

 

!

 

~

 

&&

 

||

 

??

 

?

 

:

 

=

 

+=

 

-=

 

*=

 

%=

 

**=

 

<<=

 

>>=

 

>>>=

 

&=

 

|=

 

^=

 

&&=

 

||=

 

??=

 

=>

DivPunctuator

 

::

/

/=

RightBracePunctuator

 

::

}

Per 

5.1.5

, keywords in the grammar match literal sequences of specific 

SourceCharacter

 elements.

A code point in a keyword cannot be expressed by a 

\\

 

UnicodeEscapeSequence

.

An 

IdentifierName

 can contain 

\\

 

UnicodeEscapeSequence

s, but it is not possible to declare a variable

named "else" by spelling it 

els\u{65}

els\u{65}

. The 

early error

 rules in 

13.1.1

 rule out identifiers with

the same 

StringValue

 as a reserved word.

enum

enum

 is not currently used as a keyword in this specification. It is a 

future reserved word

, set aside

for use as a keyword in future language extensions.

Similarly, 

implements

implements

interface

interface

package

package

private

private

protected

protected

, and 

public

public

 are

future reserved words in 

strict mode code

.

The names 

arguments

arguments

 and 

eval

eval

 are not keywords, but they are subject to some restrictions in

strict mode code

. See 

13.1.1

8.5.4

15.2.1

15.5.1

15.6.1

, and 

15.8.1

.

12.7  Punctuators

Syntax

12.8  Literals

12.8.1  Null Literals

Syntax

284

DecimalDigits

[Sep]

 

::

DecimalDigit
DecimalDigits

[?Sep]

 

DecimalDigit

[+Sep]

 

DecimalDigits

[+Sep]

 

NumericLiteralSeparator

 

DecimalDigit

DecimalDigit

 

::

 

one of

0

 

1

 

2

 

3

 

4

 

5

 

6

 

7

 

8

 

9

NonZeroDigit

 

::

 

one of

1

 

2

 

3

 

4

 

5

 

6

 

7

 

8

 

9

ExponentPart

[Sep]

 

::

ExponentIndicator

 

SignedInteger

[?Sep]

ExponentIndicator

 

::

 

one of

e

 

E

SignedInteger

[Sep]

 

::

DecimalDigits

[?Sep]

+

 

DecimalDigits

[?Sep]

-

 

DecimalDigits

[?Sep]

BinaryIntegerLiteral

[Sep]

 

::

0b

 

BinaryDigits

[?Sep]

0B

 

BinaryDigits

[?Sep]

BinaryDigits

[Sep]

 

::

BinaryDigit
BinaryDigits

[?Sep]

 

BinaryDigit

[+Sep]

 

BinaryDigits

[+Sep]

 

NumericLiteralSeparator

 

BinaryDigit

BinaryDigit

 

::

 

one of

0

 

1

OctalIntegerLiteral

[Sep]

 

::

0o

 

OctalDigits

[?Sep]

0O

 

OctalDigits

[?Sep]

OctalDigits

[Sep]

 

::

OctalDigit
OctalDigits

[?Sep]

 

OctalDigit

[+Sep]

 

OctalDigits

[+Sep]

 

NumericLiteralSeparator

 

OctalDigit

OctalDigit

 

::

 

one of

0

 

1

 

2

 

3

 

4

 

5

 

6

 

7

HexIntegerLiteral

[Sep]

 

::

286

0x

 

HexDigits

[?Sep]

0X

 

HexDigits

[?Sep]

HexDigits

[Sep]

 

::

HexDigit
HexDigits

[?Sep]

 

HexDigit

[+Sep]

 

HexDigits

[+Sep]

 

NumericLiteralSeparator

 

HexDigit

HexDigit

 

::

 

one of

0

 

1

 

2

 

3

 

4

 

5

 

6

 

7

 

8

 

9

 

a

 

b

 

c

 

d

 

e

 

f

 

A

 

B

 

C

 

D

 

E

 

F

The 

SourceCharacter

 immediately following a 

NumericLiteral

 must not be an 

IdentifierStart

 or 

DecimalDigit

.

NOTE

A conforming implementation, when processing 

strict mode code

, must not extend, as described in 

B.1.1

, the syntax of

NumericLiteral

 to include 

LegacyOctalIntegerLiteral

, nor extend the syntax of 

DecimalIntegerLiteral

 to include 

NonOctalDecimalIntegerLiteral

.

A numeric literal stands for a value of the Number type or the BigInt type.

The MV of 

NumericLiteral

 

::

 

DecimalLiteral

 is the MV of 

DecimalLiteral

.

The MV of 

NonDecimalIntegerLiteral

 

::

 

BinaryIntegerLiteral

 is the MV of 

BinaryIntegerLiteral

.

The MV of 

NonDecimalIntegerLiteral

 

::

 

OctalIntegerLiteral

 is the MV of 

OctalIntegerLiteral

.

The MV of 

NonDecimalIntegerLiteral

 

::

 

HexIntegerLiteral

 is the MV of 

HexIntegerLiteral

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 

.

 is the MV of 

DecimalIntegerLiteral

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 

.

 

DecimalDigits

 is the MV of 

DecimalIntegerLiteral

 plus (the

MV of 

DecimalDigits

 

×

 10

-

n

), where 

n

 is the number of code points in 

DecimalDigits

, excluding all occurrences of

NumericLiteralSeparator

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 

.

 

ExponentPart

 is the MV of 

DecimalIntegerLiteral

 

×

 10

e

,

where 

e

 is the MV of 

ExponentPart

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 

.

 

DecimalDigits

 

ExponentPart

 is (the MV of 

DecimalIntegerLiteral

 plus (the MV of 

DecimalDigits

 

×

 10

-

n

)) 

×

 10

e

, where 

n

 is the number of code points in 

DecimalDigits

, excluding all occurrences of 

NumericLiteralSeparator

 and 

e

 is the MV of 

ExponentPart

.

The MV of 

DecimalLiteral

 

::

 

.

 

DecimalDigits

 is the MV of 

DecimalDigits

 

×

 10

-

n

, where 

n

 is the number of code

points in 

DecimalDigits

, excluding all occurrences of 

NumericLiteralSeparator

.

The MV of 

DecimalLiteral

 

::

 

.

 

DecimalDigits

 

ExponentPart

 is the MV of 

DecimalDigits

 

×

 10

e

 - 

n

, where 

n

 is the

number of code points in 

DecimalDigits

, excluding all occurrences of 

NumericLiteralSeparator

, and 

e

 is the MV of 

ExponentPart

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 is the MV of 

DecimalIntegerLiteral

.

The MV of 

DecimalLiteral

 

::

 

DecimalIntegerLiteral

 

ExponentPart

 is the MV of 

DecimalIntegerLiteral

 

×

 10

e

, where

e

 is the MV of 

ExponentPart

.

The MV of 

DecimalIntegerLiteral

 

::

 

0

 is 0.

The MV of 

DecimalIntegerLiteral

 

::

 

NonZeroDigit

 is the MV of 

NonZeroDigit

.

The MV of 

DecimalIntegerLiteral

 

::

 

NonZeroDigit

 

NumericLiteralSeparator

opt

 

DecimalDigits

 is (the MV of 

For example: 

3in

3in

 is an error and not the two input elements 

33

 and 

in

in

.

12.8.3.1  Static Semantics: MV

287

NonZeroDigit

 

×

 10

n

) plus the MV of 

DecimalDigits

, where 

n

 is the number of code points in 

DecimalDigits

,

excluding all occurrences of 

NumericLiteralSeparator

.

The MV of 

DecimalDigits

 

::

 

DecimalDigit

 is the MV of 

DecimalDigit

.

The MV of 

DecimalDigits

 

::

 

DecimalDigits

 

DecimalDigit

 is (the MV of 

DecimalDigits

 

×

 10) plus the MV of 

DecimalDigit

.

The MV of 

DecimalDigits

 

::

 

DecimalDigits

 

NumericLiteralSeparator

 

DecimalDigit

 is (the MV of 

DecimalDigits

 

×

10) plus the MV of 

DecimalDigit

.

The MV of 

ExponentPart

 

::

 

ExponentIndicator

 

SignedInteger

 is the MV of 

SignedInteger

.

The MV of 

SignedInteger

 

::

 

DecimalDigits

 is the MV of 

DecimalDigits

.

The MV of 

SignedInteger

 

::

 

+

 

DecimalDigits

 is the MV of 

DecimalDigits

.

The MV of 

SignedInteger

 

::

 

-

 

DecimalDigits

 is the negative of the MV of 

DecimalDigits

.

The MV of 

DecimalDigit

 

::

 

0

 or of 

HexDigit

 

::

 

0

 or of 

OctalDigit

 

::

 

0

 or of 

BinaryDigit

 

::

 

0

 is 0.

The MV of 

DecimalDigit

 

::

 

1

 or of 

NonZeroDigit

 

::

 

1

 or of 

HexDigit

 

::

 

1

 or of 

OctalDigit

 

::

 

1

 or of

BinaryDigit

 

::

 

1

 is 1.

The MV of 

DecimalDigit

 

::

 

2

 or of 

NonZeroDigit

 

::

 

2

 or of 

HexDigit

 

::

 

2

 or of 

OctalDigit

 

::

 

2

 is 2.

The MV of 

DecimalDigit

 

::

 

3

 or of 

NonZeroDigit

 

::

 

3

 or of 

HexDigit

 

::

 

3

 or of 

OctalDigit

 

::

 

3

 is 3.

The MV of 

DecimalDigit

 

::

 

4

 or of 

NonZeroDigit

 

::

 

4

 or of 

HexDigit

 

::

 

4

 or of 

OctalDigit

 

::

 

4

 is 4.

The MV of 

DecimalDigit

 

::

 

5

 or of 

NonZeroDigit

 

::

 

5

 or of 

HexDigit

 

::

 

5

 or of 

OctalDigit

 

::

 

5

 is 5.

The MV of 

DecimalDigit

 

::

 

6

 or of 

NonZeroDigit

 

::

 

6

 or of 

HexDigit

 

::

 

6

 or of 

OctalDigit

 

::

 

6

 is 6.

The MV of 

DecimalDigit

 

::

 

7

 or of 

NonZeroDigit

 

::

 

7

 or of 

HexDigit

 

::

 

7

 or of 

OctalDigit

 

::

 

7

 is 7.

The MV of 

DecimalDigit

 

::

 

8

 or of 

NonZeroDigit

 

::

 

8

 or of 

HexDigit

 

::

 

8

 is 8.

The MV of 

DecimalDigit

 

::

 

9

 or of 

NonZeroDigit

 

::

 

9

 or of 

HexDigit

 

::

 

9

 is 9.

The MV of 

HexDigit

 

::

 

a

 or of 

HexDigit

 

::

 

A

 is 10.

The MV of 

HexDigit

 

::

 

b

 or of 

HexDigit

 

::

 

B

 is 11.

The MV of 

HexDigit

 

::

 

c

 or of 

HexDigit

 

::

 

C

 is 12.

The MV of 

HexDigit

 

::

 

d

 or of 

HexDigit

 

::

 

D

 is 13.

The MV of 

HexDigit

 

::

 

e

 or of 

HexDigit

 

::

 

E

 is 14.

The MV of 

HexDigit

 

::

 

f

 or of 

HexDigit

 

::

 

F

 is 15.

The MV of 

BinaryIntegerLiteral

 

::

 

0b

 

BinaryDigits

 is the MV of 

BinaryDigits

.

The MV of 

BinaryIntegerLiteral

 

::

 

0B

 

BinaryDigits

 is the MV of 

BinaryDigits

.

The MV of 

BinaryDigits

 

::

 

BinaryDigit

 is the MV of 

BinaryDigit

.

The MV of 

BinaryDigits

 

::

 

BinaryDigits

 

BinaryDigit

 is (the MV of 

BinaryDigits

 

×

 2) plus the MV of 

BinaryDigit

.

The MV of 

BinaryDigits

 

::

 

BinaryDigits

 

NumericLiteralSeparator

 

BinaryDigit

 is (the MV of 

BinaryDigits

 

×

 2)

plus the MV of 

BinaryDigit

.

The MV of 

OctalIntegerLiteral

 

::

 

0o

 

OctalDigits

 is the MV of 

OctalDigits

.

The MV of 

OctalIntegerLiteral

 

::

 

0O

 

OctalDigits

 is the MV of 

OctalDigits

.

The MV of 

OctalDigits

 

::

 

OctalDigit

 is the MV of 

OctalDigit

.

The MV of 

OctalDigits

 

::

 

OctalDigits

 

OctalDigit

 is (the MV of 

OctalDigits

 

×

 8) plus the MV of 

OctalDigit

.

The MV of 

OctalDigits

 

::

 

OctalDigits

 

NumericLiteralSeparator

 

OctalDigit

 is (the MV of 

OctalDigits

 

×

 8) plus the

MV of 

OctalDigit

.

The MV of 

HexIntegerLiteral

 

::

 

0x

 

HexDigits

 is the MV of 

HexDigits

.

The MV of 

HexIntegerLiteral

 

::

 

0X

 

HexDigits

 is the MV of 

HexDigits

.

The MV of 

HexDigits

 

::

 

HexDigit

 is the MV of 

HexDigit

.

The MV of 

HexDigits

 

::

 

HexDigits

 

HexDigit

 is (the MV of 

HexDigits

 

×

 16) plus the MV of 

HexDigit

.

The MV of 

HexDigits

 

::

 

HexDigits

 

NumericLiteralSeparator

 

HexDigit

 is (the MV of 

HexDigits

 

×

 16) plus the MV

of 

HexDigit

.

288

NumericLiteral

 

::

 

DecimalLiteral

1.  Return the 

Number value

 that results from rounding the MV of 

DecimalLiteral

 as described below.

NumericLiteral

 

::

 

NonDecimalIntegerLiteral

1.  Return the 

Number value

 that results from rounding the MV of 

NonDecimalIntegerLiteral

 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

𝔽

; otherwise, the rounded value must be the 

Number value

 for the MV (as

specified in 

6.1.6.1

), unless the literal is a 

DecimalLiteral

 and the literal has more than 20 significant digits, in which

case the 

Number value

 may be either the 

Number value

 for the MV of a literal produced by replacing each significant

digit after the 20th with a 

00

 digit or the 

Number value

 for the MV of a literal produced by replacing each significant

digit after the 20th with a 

00

 digit and then incrementing the literal at the 20th significant digit position. A digit is

significant

 if it is not part of an 

ExponentPart

 and

it is not 

00

; or

there is a non-zero digit to its left and there is a non-zero digit, not in the 

ExponentPart

, to its right.

NumericLiteral

 

::

 

NonDecimalIntegerLiteral

 

BigIntLiteralSuffix

1.  Return the BigInt value that represents the MV of 

NonDecimalIntegerLiteral

.

DecimalBigIntegerLiteral

 

::

 

0

 

BigIntLiteralSuffix

1.  Return 

0

.

DecimalBigIntegerLiteral

 

::

 

NonZeroDigit

 

BigIntLiteralSuffix

1.  Return the BigInt value that represents the MV of 

NonZeroDigit

.

DecimalBigIntegerLiteral

 

::

NonZeroDigit

 

DecimalDigits

 

BigIntLiteralSuffix

NonZeroDigit

 

NumericLiteralSeparator

 

DecimalDigits

 

BigIntLiteralSuffix

1.  Let 

n

 be the number of code points in 

DecimalDigits

, excluding all occurrences of 

NumericLiteralSeparator

.

2.  Let 

mv

 be (the MV of 

NonZeroDigit

 

×

 10) plus the MV of 

DecimalDigits

.

3.  Return 

mv

).

NOTE 1

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 

11.1.1

.

Code points belonging to the Basic Multilingual Plane are encoded as a single code unit element
of the string. All other code points are encoded as two code unit elements of the string.

12.8.3.2  Static Semantics: NumericValue

12.8.4  String Literals

289

 

 

 

 

 

 

 

Content      ..     22      23      24      25     ..