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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     10      11      12      13     ..

 

 

 

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

 

 

Table 1: Well-known Symbols

Specification Name

[[Description]]

Value and Purpose

@@asyncIterator

"Symbol.asyncIterator"

A method that returns the default AsyncIterator for an
object. Called by the semantics of the 

for

for

-

await

await

-

of

of

statement.

@@hasInstance

"Symbol.hasInstance"

A method that determines if a 

constructor

 object recognizes

an object as one of the 

constructor

's instances. Called by the

semantics of the 

instanceof

instanceof

 operator.

@@isConcatSpreadable

"Symbol.isConcatSpreadable"

A Boolean valued property that if true indicates that an
object should be flattened to its array elements by

Array.prototype.concat

Array.prototype.concat

.

@@iterator

"Symbol.iterator"

A method that returns the default Iterator for an object.
Called by the semantics of the for-of statement.

@@match

"Symbol.match"

A regular expression method that matches the regular
expression against a string. Called by the

String.prototype.match

String.prototype.match

 method.

@@matchAll

"Symbol.matchAll"

A regular expression method that returns an iterator, that
yields matches of the regular expression against a string.
Called by the 

String.prototype.matchAll

String.prototype.matchAll

method.

@@replace

"Symbol.replace"

A regular expression method that replaces matched
substrings of a string. Called by the

String.prototype.replace

String.prototype.replace

 method.

@@search

"Symbol.search"

A regular expression method that returns the index within a
string that matches the regular expression. Called by the

String.prototype.search

String.prototype.search

 method.

@@species

"Symbol.species"

A function valued property that is the 

constructor

 function

that is used to create derived objects.

@@split

"Symbol.split"

A regular expression method that splits a string at the
indices that match the regular expression. Called by the

String.prototype.split

String.prototype.split

 method.

@@toPrimitive

"Symbol.toPrimitive"

A method that converts an object to a corresponding
primitive value. Called by the 

ToPrimitive

 abstract

operation.

@@toStringTag

"Symbol.toStringTag"

A String valued property that is used in the creation of the
default string description of an object. Accessed by the
built-in method 

Object.prototype.toString

Object.prototype.toString

.

@@unscopables

"Symbol.unscopables"

An object valued property whose own and inherited
property names are property names that are excluded from
the 

with

with

 environment bindings of the associated object.

74

ECMAScript has two built-in numeric types: Number and BigInt. In this specification, every numeric type 

T

 contains a

multiplicative identity value denoted 

T

::unit. The specification types also have the following 

abstract operations

,

likewise denoted 

T

::

op

 for a given operation with specification name 

op

. All argument types are 

T

. The "Result"

column shows the return type, along with an indication if it is possible for some invocations of the operation to return
an 

abrupt completion

.

Table 2: Numeric Type Operations

Invocation Synopsis

Example

source

Invoked by the Evaluation semantics of ...

Result

T

::unaryMinus(x)

-x

-x

Unary 

--

 Operator

T

T

::bitwiseNOT(x)

~x

~x

Bitwise NOT Operator ( 

~~

 )

T

T

::exponentiate(x, y)

x ** y

x ** y

Exponentiation Operator

 and 

Math.pow ( 

base

,

exponent

 )

T

, may throw

RangeError

T

::multiply(x, y)

x * y

x * y

Multiplicative Operators

T

T

::divide(x, y)

x / y

x / y

Multiplicative Operators

T

, may throw

RangeError

T

::remainder(x, y)

x % y

x % y

Multiplicative Operators

T

, may throw

RangeError

T

::add(x, y)

x ++

x ++

++ x

++ x

x + y

x + y

Postfix Increment Operator

Prefix Increment

Operator

, and 

The Addition Operator ( 

++

 )

T

T

::subtract(x, y)

x --

x --

-- x

-- x

x - y

x - y

Postfix Decrement Operator

Prefix Decrement

Operator

, and 

The Subtraction Operator ( 

--

 )

T

T

::leftShift(x, y)

x << y

x << y

The Left Shift Operator ( 

<<

<<

 )

T

T

::signedRightShift(x, y)

x >> y

x >> y

The Signed Right Shift Operator ( 

>>

>>

 )

T

T

::unsignedRightShift(x, y)

x >>> y

x >>> y

The Unsigned Right Shift Operator ( 

>>>

>>>

 )

T

, may throw

TypeError

T

::lessThan(x, y)

x < y

x < y

x > y

x > y

x <= y

x <= y

x >= y

x >= y

Relational Operators

, via 

Abstract Relational

Comparison

Boolean or

undefined

 (for

unordered
inputs)

T

::equal(x, y)

x == y

x == y

x != y

x != y

x === y

x === y

x !== y

x !== y

Equality Operators

, via 

Strict Equality Comparison

Boolean

T

::sameValue(x, y)

Object internal methods, via 

SameValue ( 

x

y

 )

, to test

Boolean

6.1.6  Numeric Types

75

exact value equality

T

::sameValueZero(x, y)

Array, Map, and Set methods, via 

SameValueZero ( 

x

,

y

 )

, to test value equality ignoring differences among

members of the zero cohort (i.e., 

-0

𝔽

 and 

+0

𝔽

)

Boolean

T

::bitwiseAND(x, y)

x & y

x & y

Binary Bitwise Operators

T

T

::bitwiseXOR(x, y)

x ^ y

x ^ y

Binary Bitwise Operators

T

T

::bitwiseOR(x, y)

x | y

x | y

Binary Bitwise Operators

T

T

::toString(x)

String(x)

String(x)

Many expressions and built-in functions, via 

ToString

argument

 )

String

The 

T

::unit value and 

T

::

op

 operations are not a part of the ECMAScript language; they are defined here solely to aid

the specification of the semantics of the ECMAScript language. Other 

abstract operations

 are defined throughout this

specification.

Because the numeric types are in general not convertible without loss of precision or truncation, the ECMAScript
language provides no implicit conversion among these types. Programmers must explicitly call 

Number

Number

 and

BigInt

BigInt

 functions to convert among types when calling a function which requires another type.

NOTE

The Number type has exactly 18,437,736,874,454,810,627 (that is, 2

64

 - 2

53

 + 3) values, representing the double-

precision 64-bit format 

IEEE 754-2019

 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic,

except that the 9,007,199,254,740,990 (that is, 2

53

 - 2) distinct “Not-a-Number” values of the IEEE Standard are

represented in ECMAScript as a single special 

NaN

 value. (Note that the 

NaN

 value is produced by the program

expression 

NaN

NaN

.) In some implementations, external code might be able to detect a difference between various Not-a-

Number values, but such behaviour is 

implementation-defined

; to ECMAScript code, all 

NaN

 values are

indistinguishable from each other.

NOTE

There are two other special values, called 

positive Infinity

 and 

negative Infinity

. For brevity, these values are also

referred to for expository purposes by the symbols 

+

𝔽

 and 

-

𝔽

, respectively. (Note that these two infinite Number

values are produced by the program expressions 

+Infinity

+Infinity

 (or simply 

Infinity

Infinity

) and 

-Infinity

-Infinity

.)

The first and subsequent editions of ECMAScript have provided, for certain operators, implicit
numeric conversions that could lose precision or truncate. These legacy implicit conversions are
maintained for backward compatibility, but not provided for BigInt in order to minimize
opportunity for programmer error, and to leave open the option of generalized 

value types

 in a

future edition.

The bit pattern that might be observed in an ArrayBuffer (see 

25.1

) or a SharedArrayBuffer (see

25.2

) after a 

Number value

 has been stored into it is not necessarily the same as the internal

representation of that 

Number value

 used by the ECMAScript implementation.

6.1.6.1  The Number Type

76

The other 18,437,736,874,454,810,624 (that is, 2

64

 - 2

53

) values are called the finite numbers. Half of these are positive

numbers and half are negative numbers; for every finite positive 

Number value

 there is a corresponding negative

value having the same magnitude.

Note that there is both a 

positive zero

 and a 

negative zero

. For brevity, these values are also referred to for expository

purposes by the symbols 

+0

𝔽

 and 

-0

𝔽

, respectively. (Note that these two different zero Number values are produced by

the program expressions 

+0

+0

 (or simply 

00

) and 

-0

-0

.)

The 18,437,736,874,454,810,622 (that is, 2

64

 - 2

53

 - 2) finite non-zero values are of two kinds:

18,428,729,675,200,069,632 (that is, 2

64

 - 2

54

) of them are normalized, having the form

s

 

×

 

m

 

×

 2

e

where 

s

 is 1 or -1, 

m

 is an 

integer

 such that 2

52

 

 

m

 < 2

53

, and 

e

 is an 

integer

 such that -1074 

 

e

 

 971.

The remaining 9,007,199,254,740,990 (that is, 2

53

 - 2) values are denormalized, having the form

s

 

×

 

m

 

×

 2

e

where 

s

 is 1 or -1, 

m

 is an 

integer

 such that 0 < 

m

 < 2

52

, and 

e

 is -1074.

Note that all the positive and negative integers whose magnitude is no greater than 2

53

 are representable in the

Number type. The 

integer

 0 has two representations in the Number type: 

+0

𝔽

 and 

-0

𝔽

.

A finite number has an 

odd significand

 if it is non-zero and the 

integer

 

m

 used to express it (in one of the two forms

shown above) is odd. Otherwise, it has an 

even significand

.

In this specification, the phrase “the 

Number value

 for 

x

” where 

x

 represents an exact real mathematical quantity

(which might even be an irrational number such as 

π

) means a 

Number value

 chosen in the following manner.

Consider the set of all finite values of the Number type, with 

-0

𝔽

 removed and with two additional values added to it

that are not representable in the Number type, namely 2

1024

 (which is +1 

×

 2

53

 

×

 2

971

) and -2

1024

 (which is -1 

×

 2

53

 

×

2

971

). Choose the member of this set that is closest in value to 

x

. If two values of the set are equally close, then the one

with an even significand is chosen; for this purpose, the two extra values 2

1024

 and -2

1024

 are considered to have even

significands. Finally, if 2

1024

 was chosen, replace it with 

+

𝔽

; if -2

1024

 was chosen, replace it with 

-

𝔽

; if 

+0

𝔽

 was

chosen, replace it with 

-0

𝔽

 if and only if 

x

 < 0; any other chosen value is used unchanged. The result is the 

Number

value

 for 

x

. (This procedure corresponds exactly to the behaviour of the 

IEEE 754-2019

 roundTiesToEven mode.)

The 

Number value

 for +

 is 

+

𝔽

, and the 

Number value

 for -

 is 

-

𝔽

.

Some ECMAScript operators deal only with integers in specific ranges such as -2

31

 through 2

31

 - 1, inclusive, or in the

range 0 through 2

16

 - 1, inclusive. These operators accept any value of the Number type but first convert each such

value to an 

integer

 value in the expected range. See the descriptions of the numeric conversion operations in 

7.1

.

The Number::unit value is 

1

𝔽

.

The abstract operation Number::unaryMinus takes argument 

x

 (a Number). It performs the following steps when

called:

6.1.6.1.1  Number::unaryMinus ( 

x

 )

77

1.  If 

x

 is 

NaN

, return 

NaN

.

2.  Return the result of negating 

x

; that is, compute a Number with the same magnitude but opposite sign.

The abstract operation Number::bitwiseNOT takes argument 

x

 (a Number). It performs the following steps when

called:

1.  Let 

oldValue

 be ! 

ToInt32

(

x

).

2.  Return the result of applying bitwise complement to 

oldValue

. The 

mathematical value

 of the result is exactly

representable as a 32-bit two's complement bit string.

The abstract operation Number::exponentiate takes arguments 

base

 (a Number) and 

exponent

 (a Number). It returns an

implementation-approximated

 value representing the result of raising 

base

 to the 

exponent

 power. It performs the

following steps when called:

1.  If 

exponent

 is 

NaN

, return 

NaN

.

2.  If 

exponent

 is 

+0

𝔽

 or 

exponent

 is 

-0

𝔽

, return 

1

𝔽

.

3.  If 

base

 is 

NaN

, return 

NaN

.

4.  If 

base

 is 

+

𝔽

, then

a.  If 

exponent

 > 

+0

𝔽

, return 

+

𝔽

. Otherwise, return 

+0

𝔽

.

5.  If 

base

 is 

-

𝔽

, then

a.  If 

exponent

 > 

+0

𝔽

, then

i.  If 

exponent

 is an odd 

integral Number

, return 

-

𝔽

. Otherwise, return 

+

𝔽

.

b.  Else,

i.  If 

exponent

 is an odd 

integral Number

, return 

-0

𝔽

. Otherwise, return 

+0

𝔽

.

6.  If 

base

 is 

+0

𝔽

, then

a.  If 

exponent

 > 

+0

𝔽

, return 

+0

𝔽

. Otherwise, return 

+

𝔽

.

7.  If 

base

 is 

-0

𝔽

, then

a.  If 

exponent

 > 

+0

𝔽

, then

i.  If 

exponent

 is an odd 

integral Number

, return 

-0

𝔽

. Otherwise, return 

+0

𝔽

.

b.  Else,

i.  If 

exponent

 is an odd 

integral Number

, return 

-

𝔽

. Otherwise, return 

+

𝔽

.

8. 

Assert

base

 is finite and is neither 

+0

𝔽

 nor 

-0

𝔽

.

9.  If 

exponent

 is 

+

𝔽

, then

a.  If 

abs

(

base

)) > 1, return 

+

𝔽

.

b.  If 

abs

(

base

)) is 1, return 

NaN

.

c.  If 

abs

(

base

)) < 1, return 

+0

𝔽

.

10.  If 

exponent

 is 

-

𝔽

, then

a.  If 

abs

(

base

)) > 1, return 

+0

𝔽

.

b.  If 

abs

(

base

)) is 1, return 

NaN

.

c.  If 

abs

(

base

)) < 1, return 

+

𝔽

.

11. 

Assert

exponent

 is finite and is neither 

+0

𝔽

 nor 

-0

𝔽

.

12.  If 

base

 < 

+0

𝔽

 and 

exponent

 is not an 

integral Number

, return 

NaN

.

13.  Return an 

implementation-approximated

 value representing the result of raising 

base

) to the 

exponent

)

6.1.6.1.2  Number::bitwiseNOT ( 

x

 )

6.1.6.1.3  Number::exponentiate ( 

base

exponent

 )

78

power.

NOTE

The abstract operation Number::multiply takes arguments 

x

 (a Number) and 

y

 (a Number). It performs multiplication

according to the rules of 

IEEE 754-2019

 binary double-precision arithmetic, producing the product of 

x

 and 

y

. It

performs the following steps when called:

1.  If 

x

 is 

NaN

 or 

y

 is 

NaN

, return 

NaN

.

2.  If 

x

 is 

+

𝔽

 or 

x

 is 

-

𝔽

, then

a.  If 

y

 is 

+0

𝔽

 or 

y

 is 

-0

𝔽

, return 

NaN

.

b.  If 

y

 > 

+0

𝔽

, return 

x

.

c.  Return -

x

.

3.  If 

y

 is 

+

𝔽

 or 

y

 is 

-

𝔽

, then

a.  If 

x

 is 

+0

𝔽

 or 

x

 is 

-0

𝔽

, return 

NaN

.

b.  If 

x

 > 

+0

𝔽

, return 

y

.

c.  Return -

y

.

4.  Return 

(

x

×

 

(

y

)).

NOTE

The abstract operation Number::divide takes arguments 

x

 (a Number) and 

y

 (a Number). It performs division

according to the rules of 

IEEE 754-2019

 binary double-precision arithmetic, producing the quotient of 

x

 and 

y

 where 

x

is the dividend and 

y

 is the divisor. It performs the following steps when called:

1.  If 

x

 is 

NaN

 or 

y

 is 

NaN

, return 

NaN

.

2.  If 

x

 is 

+

𝔽

 or 

x

 is 

-

𝔽

, then

a.  If 

y

 is 

+

𝔽

 or 

y

 is 

-

𝔽

, return 

NaN

.

b.  If 

y

 is 

+0

𝔽

 or 

y

 > 

+0

𝔽

, return 

x

.

c.  Return -

x

.

3.  If 

y

 is 

+

𝔽

, then

a.  If 

x

 is 

+0

𝔽

 or 

x

 > 

+0

𝔽

, return 

+0

𝔽

. Otherwise, return 

-0

𝔽

.

4.  If 

y

 is 

-

𝔽

, then

a.  If 

x

 is 

+0

𝔽

 or 

x

 > 

+0

𝔽

, return 

-0

𝔽

. Otherwise, return 

+0

𝔽

.

5.  If 

x

 is 

+0

𝔽

 or 

x

 is 

-0

𝔽

, then

a.  If 

y

 is 

+0

𝔽

 or 

y

 is 

-0

𝔽

, return 

NaN

.

b.  If 

y

 > 

+0

𝔽

, return 

x

.

c.  Return -

x

.

6.  If 

y

 is 

+0

𝔽

, then

The result of 

base

 

**

**

 

exponent

 when 

base

 is 

1

𝔽

 or 

-1

𝔽

 and 

exponent

 is 

+

𝔽

 or 

-

𝔽

, or when 

base

 is 

1

𝔽

and 

exponent

 is 

NaN

, differs from 

IEEE 754-2019

. The first edition of ECMAScript specified a

result of 

NaN

 for this operation, whereas later versions of 

IEEE 754-2019

 specified 

1

𝔽

. The

historical ECMAScript behaviour is preserved for compatibility reasons.

Finite-precision multiplication is commutative, but not always associative.

6.1.6.1.4  Number::multiply ( 

x

y

 )

6.1.6.1.5  Number::divide ( 

x

y

 )

79

a.  If 

x

 > 

+0

𝔽

, return 

+

𝔽

. Otherwise, return 

-

𝔽

.

7.  If 

y

 is 

-0

𝔽

, then

a.  If 

x

 > 

+0

𝔽

, return 

-

𝔽

. Otherwise, return 

+

𝔽

.

8.  Return 

(

x

) / 

(

y

)).

The abstract operation Number::remainder takes arguments 

n

 (a Number) and 

d

 (a Number). It yields the remainder

from an implied division of its operands where 

n

 is the dividend and 

d

 is the divisor. It performs the following steps

when called:

1.  If 

n

 is 

NaN

 or 

d

 is 

NaN

, return 

NaN

.

2.  If 

n

 is 

+

𝔽

 or 

n

 is 

-

𝔽

, return 

NaN

.

3.  If 

d

 is 

+

𝔽

 or 

d

 is 

-

𝔽

, return 

n

.

4.  If 

d

 is 

+0

𝔽

 or 

d

 is 

-0

𝔽

, return 

NaN

.

5.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

n

.

6. 

Assert

n

 and 

d

 are finite and non-zero.

7.  Let 

r

 be 

(

n

) - (

(

d

×

 

q

) where 

q

 is an 

integer

 that is negative if and only if 

n

 and 

d

 have opposite sign, and

n

) / 

(

d

).

8.  Return 

r

).

NOTE 1

NOTE 2

The abstract operation Number::add takes arguments 

x

 (a Number) and 

y

 (a Number). It performs addition according

to the rules of 

IEEE 754-2019

 binary double-precision arithmetic, producing the sum of its arguments. It performs the

following steps when called:

1.  If 

x

 is 

NaN

 or 

y

 is 

NaN

, return 

NaN

.

2.  If 

x

 is 

+

𝔽

 and 

y

 is 

-

𝔽

, return 

NaN

.

3.  If 

x

 is 

-

𝔽

 and 

y

 is 

+

𝔽

, return 

NaN

.

4.  If 

x

 is 

+

𝔽

 or 

x

 is 

-

𝔽

, return 

x

.

5.  If 

y

 is 

+

𝔽

 or 

y

 is 

-

𝔽

, return 

y

.

6. 

Assert

x

 and 

y

 are both finite.

7.  If 

x

 is 

-0

𝔽

 and 

y

 is 

-0

𝔽

, return 

-0

𝔽

.

8.  Return 

(

x

) + 

(

y

)).

In C and C++, the remainder operator accepts only integral operands; in ECMAScript, it also
accepts floating-point operands.

The result of a floating-point remainder operation as computed by the 

%%

 operator is not the same

as the “remainder” operation defined by 

IEEE 754-2019

. The 

IEEE 754-2019

 “remainder”

operation computes the remainder from a rounding division, not a truncating division, and so its
behaviour is not analogous to that of the usual integer remainder operator. Instead the
ECMAScript language defines 

%%

 on floating-point operations to behave in a manner analogous to

that of the Java integer remainder operator; this may be compared with the C library function
fmod.

6.1.6.1.6  Number::remainder ( 

n

d

 )

6.1.6.1.7  Number::add ( 

x

y

 )

80

NOTE

The abstract operation Number::subtract takes arguments 

x

 (a Number) and 

y

 (a Number). It performs subtraction,

producing the difference of its operands; 

x

 is the minuend and 

y

 is the subtrahend. It performs the following steps

when called:

1.  Return Number::add(

x

, Number::unaryMinus(

y

)).

NOTE

The abstract operation Number::leftShift takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the following

steps when called:

1.  Let 

lnum

 be ! 

ToInt32

(

x

).

2.  Let 

rnum

 be ! 

ToUint32

(

y

).

3.  Let 

shiftCount

rnum

modulo

 32.

4.  Return the result of left shifting 

lnum

 by 

shiftCount

 bits. The 

mathematical value

 of the result is exactly

representable as a 32-bit two's complement bit string.

The abstract operation Number::signedRightShift takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  Let 

lnum

 be ! 

ToInt32

(

x

).

2.  Let 

rnum

 be ! 

ToUint32

(

y

).

3.  Let 

shiftCount

rnum

modulo

 32.

4.  Return the result of performing a sign-extending right shift of 

lnum

 by 

shiftCount

 bits. The most significant bit

is propagated. The 

mathematical value

 of the result is exactly representable as a 32-bit two's complement bit

string.

The abstract operation Number::unsignedRightShift takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  Let 

lnum

 be ! 

ToUint32

(

x

).

2.  Let 

rnum

 be ! 

ToUint32

(

y

).

3.  Let 

shiftCount

rnum

modulo

 32.

4.  Return the result of performing a zero-filling right shift of 

lnum

 by 

shiftCount

 bits. Vacated bits are filled with

zero. The 

mathematical value

 of the result is exactly representable as a 32-bit unsigned bit string.

The abstract operation Number::lessThan takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the following

Finite-precision addition is commutative, but not always associative.

It is always the case that 

x - y

x - y

 produces the same result as 

x + (-y)

x + (-y)

.

6.1.6.1.8  Number::subtract ( 

x

y

 )

6.1.6.1.9  Number::leftShift ( 

x

y

 )

6.1.6.1.10  Number::signedRightShift ( 

x

y

 )

6.1.6.1.11  Number::unsignedRightShift ( 

x

y

 )

6.1.6.1.12  Number::lessThan ( 

x

y

 )

81

steps when called:

1.  If 

x

 is 

NaN

, return 

undefined

.

2.  If 

y

 is 

NaN

, return 

undefined

.

3.  If 

x

 and 

y

 are the same 

Number value

, return 

false

.

4.  If 

x

 is 

+0

𝔽

 and 

y

 is 

-0

𝔽

, return 

false

.

5.  If 

x

 is 

-0

𝔽

 and 

y

 is 

+0

𝔽

, return 

false

.

6.  If 

x

 is 

+

𝔽

, return 

false

.

7.  If 

y

 is 

+

𝔽

, return 

true

.

8.  If 

y

 is 

-

𝔽

, return 

false

.

9.  If 

x

 is 

-

𝔽

, return 

true

.

10. 

Assert

x

 and 

y

 are finite and non-zero.

x

y

), return 

true

. Otherwise, return 

false

.

The abstract operation Number::equal takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the following

steps when called:

1.  If 

x

 is 

NaN

, return 

false

.

2.  If 

y

 is 

NaN

, return 

false

.

3.  If 

x

 is the same 

Number value

 as 

y

, return 

true

.

4.  If 

x

 is 

+0

𝔽

 and 

y

 is 

-0

𝔽

, return 

true

.

5.  If 

x

 is 

-0

𝔽

 and 

y

 is 

+0

𝔽

, return 

true

.

6.  Return 

false

.

The abstract operation Number::sameValue takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  If 

x

 is 

NaN

 and 

y

 is 

NaN

, return 

true

.

2.  If 

x

 is 

+0

𝔽

 and 

y

 is 

-0

𝔽

, return 

false

.

3.  If 

x

 is 

-0

𝔽

 and 

y

 is 

+0

𝔽

, return 

false

.

4.  If 

x

 is the same 

Number value

 as 

y

, return 

true

.

5.  Return 

false

.

The abstract operation Number::sameValueZero takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  If 

x

 is 

NaN

 and 

y

 is 

NaN

, return 

true

.

2.  If 

x

 is 

+0

𝔽

 and 

y

 is 

-0

𝔽

, return 

true

.

3.  If 

x

 is 

-0

𝔽

 and 

y

 is 

+0

𝔽

, return 

true

.

4.  If 

x

 is the same 

Number value

 as 

y

, return 

true

.

5.  Return 

false

.

6.1.6.1.13  Number::equal ( 

x

y

 )

6.1.6.1.14  Number::sameValue ( 

x

y

 )

6.1.6.1.15  Number::sameValueZero ( 

x

y

 )

6.1.6.1.16  NumberBitwiseOp ( 

op

x

y

 )

82

The abstract operation NumberBitwiseOp takes arguments 

op

 (a sequence of Unicode code points), 

x

, and 

y

. It

performs the following steps when called:

1. 

Assert

op

 is 

&&

^^

, or 

||

.

2.  Let 

lnum

 be ! 

ToInt32

(

x

).

3.  Let 

rnum

 be ! 

ToInt32

(

y

).

4.  Let 

lbits

 be the 32-bit two's complement bit string representing 

lnum

).

5.  Let 

rbits

rnum

).

6.  If 

op

 is 

&&

, let 

result

 be the result of applying the bitwise AND operation to 

lbits

 and 

rbits

.

7.  Else if 

op

 is 

^^

, let 

result

 be the result of applying the bitwise exclusive OR (XOR) operation to 

lbits

 and 

rbits

.

8.  Else, 

op

 is 

||

. Let 

result

 be the result of applying the bitwise inclusive OR operation to 

lbits

 and 

rbits

.

9.  Return the 

Number value

 for the 

integer

 represented by the 32-bit two's complement bit string 

result

.

The abstract operation Number::bitwiseAND takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  Return 

NumberBitwiseOp

(

&&

x

y

).

The abstract operation Number::bitwiseXOR takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  Return 

NumberBitwiseOp

(

^^

x

y

).

The abstract operation Number::bitwiseOR takes arguments 

x

 (a Number) and 

y

 (a Number). It performs the

following steps when called:

1.  Return 

NumberBitwiseOp

(

||

x

y

).

The abstract operation Number::toString takes argument 

x

 (a Number). It converts 

x

 to String format. It performs the

following steps when called:

1.  If 

x

 is 

NaN

, return the String 

"NaN"

.

2.  If 

x

 is 

+0

𝔽

 or 

-0

𝔽

, return the String 

"0"

.

3.  If 

x

 < 

+0

𝔽

, return the 

string-concatenation

 of 

"-"

 and ! 

Number::toString

(-

x

).

4.  If 

x

 is 

+

𝔽

, return the String 

"Infinity"

.

5.  Otherwise, let 

n

k

, and 

s

 be integers such that 

k

 

 1, 10

k

 - 1

 

 

s

 < 10

k

s

 

×

 10

n

 - 

k

 is 

(

x

), and 

k

 is as small as

possible. Note that 

k

 is the number of digits in the decimal representation of 

s

, that 

s

 is not divisible by 10, and

that the least significant digit of 

s

 is not necessarily uniquely determined by these criteria.

6.  If 

k

 

 

n

 

 21, return the 

string-concatenation

 of:

the code units of the 

k

 digits of the decimal representation of 

s

 (in order, with no leading zeroes)

n

 - 

k

 occurrences of the code unit 0x0030 (DIGIT ZERO)

7.  If 0 < 

n

 

 21, return the 

string-concatenation

 of:

6.1.6.1.17  Number::bitwiseAND ( 

x

y

 )

6.1.6.1.18  Number::bitwiseXOR ( 

x

y

 )

6.1.6.1.19  Number::bitwiseOR ( 

x

y

 )

6.1.6.1.20  Number::toString ( 

x

 )

83

the code units of the most significant 

n

 digits of the decimal representation of 

s

the code unit 0x002E (FULL STOP)
the code units of the remaining 

k

 - 

n

 digits of the decimal representation of 

s

8.  If -6 < 

n

 

 0, return the 

string-concatenation

 of:

the code unit 0x0030 (DIGIT ZERO)
the code unit 0x002E (FULL STOP)
-

n

 occurrences of the code unit 0x0030 (DIGIT ZERO)

the code units of the 

k

 digits of the decimal representation of 

s

9.  Otherwise, if 

k

 = 1, return the 

string-concatenation

 of:

the code unit of the single digit of 

s

the code unit 0x0065 (LATIN SMALL LETTER E)
the code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether 

n

 -

1 is positive or negative
the code units of the decimal representation of the 

integer

 

abs

(

n

 - 1) (with no leading zeroes)

10.  Return the 

string-concatenation

 of:

the code units of the most significant digit of the decimal representation of 

s

the code unit 0x002E (FULL STOP)
the code units of the remaining 

k

 - 1 digits of the decimal representation of 

s

the code unit 0x0065 (LATIN SMALL LETTER E)
the code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether 

n

 -

1 is positive or negative
the code units of the decimal representation of the 

integer

 

abs

(

n

 - 1) (with no leading zeroes)

NOTE 1

NOTE 2

The following observations may be useful as guidelines for implementations, but are not part of
the normative requirements of this Standard:

If x is any 

Number value

 other than 

-0

𝔽

, then 

ToNumber

(

ToString

(x)) is exactly the same

Number value

 as x.

The least significant digit of s is not always uniquely determined by the requirements
listed in step 

5

.

For implementations that provide more accurate conversions than required by the rules above, it
is recommended that the following alternative version of step 

5

 be used as a guideline:

5.  Otherwise, let 

n

k

, and 

s

 be integers such that 

k

 

 1, 10

k

 - 1

 

 

s

 < 10

k

s

 

×

 10

n

 - 

k

 is 

(

x

), and 

k

is as small as possible. If there are multiple possibilities for 

s

, choose the value of 

s

 for

which 

s

 

×

 10

n

 - 

k

x

). If there are two such possible values of 

s

, choose

the one that is even. Note that 

k

 is the number of digits in the decimal representation of 

s

and that 

s

 is not divisible by 10.

84

NOTE 3

The BigInt type represents an 

integer

 value. The value may be any size and is not limited to a particular bit-width.

Generally, where not otherwise noted, operations are designed to return exact mathematically-based answers. For
binary operations, BigInts act as two's complement binary strings, with negative numbers treated as having bits set
infinitely to the left.

The BigInt::unit value is 

1

.

The abstract operation BigInt::unaryMinus takes argument 

x

 (a BigInt). It performs the following steps when called:

1.  If 

x

 is 

0

, return 

0

.

x

).

The abstract operation BigInt::bitwiseNOT takes argument 

x

 (a BigInt). It returns the one's complement of 

x

; that is, -

x

1

.

The abstract operation BigInt::exponentiate takes arguments 

base

 (a BigInt) and 

exponent

 (a BigInt). It performs the

following steps when called:

1.  If 

exponent

 < 

0

, throw a 

RangeError

 exception.

2.  If 

base

 is 

0

 and 

exponent

 is 

0

, return 

1

.

3.  Return the BigInt value that represents 

(

base

exponent

).

The abstract operation BigInt::multiply takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It returns the BigInt value that

represents the result of multiplying 

x

 and 

y

.

NOTE

Implementers of ECMAScript may find useful the paper and code written by David M. Gay for
binary-to-decimal conversion of floating-point numbers:

Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical
Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). 30 November
1990. Available as 

http://ampl.com/REFS/abstracts.html#rounding

. Associated code available as 

http://netlib.sandia.gov/fp/dtoa.c

 and as 

http://netlib.sandia.gov/fp/g_fmt.c

 and may also be found at the various 

netlib

netlib

 mirror sites.

Even if the result has a much larger bit width than the input, the exact mathematical answer is
given.

6.1.6.2  The BigInt Type

6.1.6.2.1  BigInt::unaryMinus ( 

x

 )

6.1.6.2.2  BigInt::bitwiseNOT ( 

x

 )

6.1.6.2.3  BigInt::exponentiate ( 

base

exponent

 )

6.1.6.2.4  BigInt::multiply ( 

x

y

 )

85

The abstract operation BigInt::divide takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following steps

when called:

1.  If 

y

 is 

0

, throw a 

RangeError

 exception.

2.  Let 

quotient

x

(

y

).

3.  Return the BigInt value that represents 

quotient

 rounded towards 0 to the next 

integer

 value.

The abstract operation BigInt::remainder takes arguments 

n

 (a BigInt) and 

d

 (a BigInt). It performs the following steps

when called:

1.  If 

d

 is 

0

, throw a 

RangeError

 exception.

2.  If 

n

 is 

0

, return 

0

.

3.  Let 

r

 be the BigInt defined by the mathematical relation 

r

 = 

n

 - (

d

 

×

 

q

) where 

q

 is a BigInt that is negative only if

n

/

d

 is negative and positive only if 

n

/

d

 is positive, and whose magnitude is as large as possible without

exceeding the magnitude of the true mathematical quotient of 

n

 and 

d

.

4.  Return 

r

.

NOTE

The abstract operation BigInt::add takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It returns the BigInt value that

represents the sum of 

x

 and 

y

.

The abstract operation BigInt::subtract takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It returns the BigInt value that

represents the difference 

x

 minus 

y

.

The abstract operation BigInt::leftShift takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following steps

when called:

1.  If 

y

 < 

0

, then

a.  Return the BigInt value that represents 

(

x

) / 2

-

y

, rounding down to the nearest 

integer

, including for

negative numbers.

2.  Return the BigInt value that represents 

(

x

×

 2

y

.

NOTE

The abstract operation BigInt::signedRightShift takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following

The sign of the result equals the sign of the dividend.

Semantics here should be equivalent to a bitwise shift, treating the BigInt as an infinite length
string of binary two's complement digits.

6.1.6.2.5  BigInt::divide ( 

x

y

 )

6.1.6.2.6  BigInt::remainder ( 

n

d

 )

6.1.6.2.7  BigInt::add ( 

x

y

 )

6.1.6.2.8  BigInt::subtract ( 

x

y

 )

6.1.6.2.9  BigInt::leftShift ( 

x

y

 )

6.1.6.2.10  BigInt::signedRightShift ( 

x

y

 )

86

steps when called:

1.  Return BigInt::leftShift(

x

, -

y

).

The abstract operation BigInt::unsignedRightShift takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the

following steps when called:

1.  Throw a 

TypeError

 exception.

The abstract operation BigInt::lessThan takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It returns 

true

x

(

y

) and

false

 otherwise.

The abstract operation BigInt::equal takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It returns 

true

x

y

) and 

false

otherwise.

The abstract operation BigInt::sameValue takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following steps

when called:

1.  Return BigInt::equal(

x

y

).

The abstract operation BigInt::sameValueZero takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following

steps when called:

1.  Return BigInt::equal(

x

y

).

The abstract operation BinaryAnd takes arguments 

x

 and 

y

. It performs the following steps when called:

1. 

Assert

x

 is 0 or 1.

2. 

Assert

y

 is 0 or 1.

3.  If 

x

 is 1 and 

y

 is 1, return 1.

4.  Else, return 0.

The abstract operation BinaryOr takes arguments 

x

 and 

y

. It performs the following steps when called:

1. 

Assert

x

 is 0 or 1.

2. 

Assert

y

 is 0 or 1.

3.  If 

x

 is 1 or 

y

 is 1, return 1.

4.  Else, return 0.

6.1.6.2.11  BigInt::unsignedRightShift ( 

x

y

 )

6.1.6.2.12  BigInt::lessThan ( 

x

y

 )

6.1.6.2.13  BigInt::equal ( 

x

y

 )

6.1.6.2.14  BigInt::sameValue ( 

x

y

 )

6.1.6.2.15  BigInt::sameValueZero ( 

x

y

 )

6.1.6.2.16  BinaryAnd ( 

x

y

 )

6.1.6.2.17  BinaryOr ( 

x

y

 )

87

The abstract operation BinaryXor takes arguments 

x

 and 

y

. It performs the following steps when called:

1. 

Assert

x

 is 0 or 1.

2. 

Assert

y

 is 0 or 1.

3.  If 

x

 is 1 and 

y

 is 0, return 1.

4.  Else if 

x

 is 0 and 

y

 is 1, return 1.

5.  Else, return 0.

The abstract operation BigIntBitwiseOp takes arguments 

op

 (a sequence of Unicode code points), 

x

 (a BigInt), and 

y

 (a

BigInt). It performs the following steps when called:

1. 

Assert

op

 is 

&&

^^

, or 

||

.

2.  Set 

x

 to 

(

x

).

3.  Set 

y

 to 

(

y

).

4.  Let 

result

 be 0.

5.  Let 

shift

 be 0.

6.  Repeat, until (

x

 = 0 or 

x

 = -1) and (

y

 = 0 or 

y

 = -1),

a.  Let 

xDigit

 be 

x

 

modulo

 2.

b.  Let 

yDigit

 be 

y

 

modulo

 2.

c.  If 

op

 is 

&&

, set 

result

 to 

result

 + 2

shift

 

×

 

BinaryAnd

(

xDigit

yDigit

).

d.  Else if 

op

 is 

||

, set 

result

 to 

result

 + 2

shift

 

×

 

BinaryOr

(

xDigit

yDigit

).

e.  Else,

i. 

Assert

op

 is 

^^

.

ii.  Set 

result

 to 

result

 + 2

shift

 

×

 

BinaryXor

(

xDigit

yDigit

).

f.  Set 

shift

 to 

shift

 + 1.

g.  Set 

x

 to (

x

 - 

xDigit

) / 2.

h.  Set 

y

 to (

y

 - 

yDigit

) / 2.

7.  If 

op

 is 

&&

, let 

tmp

 be 

BinaryAnd

(

x

 

modulo

 2, 

y

 

modulo

 2).

8.  Else if 

op

 is 

||

, let 

tmp

 be 

BinaryOr

(

x

 

modulo

 2, 

y

 

modulo

 2).

9.  Else,

a. 

Assert

op

 is 

^^

.

b.  Let 

tmp

 be 

BinaryXor

(

x

 

modulo

 2, 

y

 

modulo

 2).

10.  If 

tmp

 

 0, then

a.  Set 

result

 to 

result

 - 2

shift

.

b.  NOTE: This extends the sign.

11.  Return the BigInt value for 

result

.

The abstract operation BigInt::bitwiseAND takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following

steps when called:

1.  Return 

BigIntBitwiseOp

(

&&

x

y

).

6.1.6.2.18  BinaryXor ( 

x

y

 )

6.1.6.2.19  BigIntBitwiseOp ( 

op

x

y

 )

6.1.6.2.20  BigInt::bitwiseAND ( 

x

y

 )

6.1.6.2.21  BigInt::bitwiseXOR ( 

x

y

 )

88

The abstract operation BigInt::bitwiseXOR takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following

steps when called:

1.  Return 

BigIntBitwiseOp

(

^^

x

y

).

The abstract operation BigInt::bitwiseOR takes arguments 

x

 (a BigInt) and 

y

 (a BigInt). It performs the following steps

when called:

1.  Return 

BigIntBitwiseOp

(

||

x

y

).

The abstract operation BigInt::toString takes argument 

x

 (a BigInt). It converts 

x

 to String format. It performs the

following steps when called:

1.  If 

x

 < 

0

, return the 

string-concatenation

 of the String 

"-"

 and ! 

BigInt::toString

(-

x

).

2.  Return the String value consisting of the code units of the digits of the decimal representation of 

x

.

An Object is logically a collection of properties. Each property is either a data property, or an accessor property:

data property

 associates a key value with an 

ECMAScript language value

 and a set of Boolean attributes.

An 

accessor property

 associates a key value with one or two accessor functions, and a set of Boolean attributes.

The accessor functions are used to store or retrieve an 

ECMAScript language value

 that is associated with the

property.

Properties are identified using key values. A property key value is either an ECMAScript String value or a Symbol
value. All String and Symbol values, including the empty String, are valid as property keys. A 

property name

 is a

property key that is a String value.

An 

integer index

 is a String-valued property key that is a canonical numeric String (see 

7.1.21

) and whose numeric

value is either 

+0

𝔽

 or a positive 

integral Number

 

53

 - 1). An 

array index

 is an 

integer index

 whose numeric value 

i

is in the range 

+0

𝔽

 

 

i

 < 

32

 - 1).

Property keys are used to access properties and their values. There are two kinds of access for properties: 

get

 and 

set

,

corresponding to value retrieval and assignment, respectively. The properties accessible via get and set access includes
both 

own properties

 that are a direct part of an object and 

inherited properties

 which are provided by another associated

object via a property inheritance relationship. Inherited properties may be either own or inherited properties of the
associated object. Each own property of an object must each have a key value that is distinct from the key values of the
other own properties of that object.

All objects are logically collections of properties, but there are multiple forms of objects that differ in their semantics
for accessing and manipulating their properties. Please see 

6.1.7.2

 for definitions of the multiple forms of objects.

Attributes are used in this specification to define and explain the state of Object properties. A 

data property

 associates

6.1.6.2.22  BigInt::bitwiseOR ( 

x

y

 )

6.1.6.2.23  BigInt::toString ( 

x

 )

6.1.7  The Object Type

6.1.7.1  Property Attributes

89

 

 

 

 

 

 

 

Content      ..     10      11      12      13     ..