Algorithms within this specification manipulate values each of which has an associated type. The possible value types are exactly those defined in this clause. Types are further classified into ECMAScript language types and specification types.
6.1 ECMAScript Language TypesAn ECMAScript language type corresponds to values that are directly manipulated by an ECMAScript programmer using the ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Symbol, Number, BigInt, and Object. An ECMAScript language value is a value that is characterized by an ECMAScript language type.
6.1.1 The Undefined TypeThe Undefined type has exactly one value, called undefined . Any variable that has not been assigned a value has the value undefined .
6.1.2 The Null TypeThe Null type has exactly one value, called null .
6.1.3 The Boolean TypeThe Boolean type represents a logical entity having two values, called true and false .
6.1.4 The String TypeThe String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values (“elements”) up to a maximum length of 253 - 1 elements. The String type is generally used to represent textual data in a running ECMAScript program, in which case each element in the String is treated as a UTF-16 code unit value. Each element is regarded as occupying a position within the sequence. These positions are indexed with non-negative integers . The first element (if any) is at index 0, the next element (if any) at index 1, and so on. The length of a String is the number of elements (i.e., 16-bit values) within it. The empty String has length zero and therefore contains no elements.
ECMAScript operations that do not interpret String contents apply no further semantics. Operations that do interpret String values treat each element as a single UTF-16 code unit. However, ECMAScript does not restrict the value of or relationships between these code units, so operations that further interpret String contents as sequences of Unicode code points encoded in UTF-16 must account for ill-formed subsequences. Such operations apply special treatment to every code unit with a numeric value in the inclusive interval from 0xD800 to 0xDBFF (defined by the Unicode Standard as a leading surrogate, or more formally as a high-surrogate code unit) and every code unit with a numeric value in the inclusive interval from 0xDC00 to 0xDFFF (defined as a trailing surrogate, or more formally as a low-surrogate code unit) using the following rules:
The function String.prototype.normalize
(see 22.1.3.15 ) can be used to explicitly normalize a String value. String.prototype.localeCompare
(see 22.1.3.12 ) internally normalizes String values, but no other operations implicitly normalize the strings upon which they operate. Operation results are not language- and/or locale-sensitive unless stated otherwise.
The rationale behind this design was to keep the implementation of Strings as simple and high-performing as possible. If ECMAScript source text is in Normalized Form C, string literals are guaranteed to also be normalized, as long as they do not contain any Unicode escape sequences.
In this specification, the phrase "the string-concatenation of A, B, ..." (where each argument is a String value, a code unit, or a sequence of code units) denotes the String value whose sequence of code units is the concatenation of the code units (in order) of each of the arguments (in order).
The phrase "the substring of S from inclusiveStart to exclusiveEnd" (where S is a String value or a sequence of code units and inclusiveStart and exclusiveEnd are integers ) denotes the String value consisting of the consecutive code units of S beginning at index inclusiveStart and ending immediately before index exclusiveEnd (which is the empty String when inclusiveStart = exclusiveEnd). If the "to" suffix is omitted, the length of S is used as the value of exclusiveEnd.
The phrase "the ASCII word characters" denotes the following String value, which consists solely of every letter and number in the Unicode Basic Latin block along with U+005F (LOW LINE):
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" .
For historical reasons, it has significance to various algorithms.
The abstract operation StringIndexOf takes arguments string (a String), searchValue (a String), and fromIndex (a non-negative integer ) and returns a non-negative integer or not-found . It performs the following steps when called:
If searchValue is the empty String and fromIndex ≤ the length of string, this algorithm returns fromIndex. The empty String is effectively found at every position within a string, including after the last code unit.
Note 2This algorithm always returns not-found if fromIndex + the length of searchValue > the length of string.
6.1.4.2 StringLastIndexOf ( string, searchValue, fromIndex )The abstract operation StringLastIndexOf takes arguments string (a String), searchValue (a String), and fromIndex (a non-negative integer ) and returns a non-negative integer or not-found . It performs the following steps when called:
If searchValue is the empty String, this algorithm returns fromIndex. The empty String is effectively found at every position within a string, including after the last code unit.
6.1.5 The Symbol TypeThe Symbol type is the set of all non-String values that may be used as the key of an Object property ( 6.1.7 ).
Each possible Symbol value is unique and immutable.
Each Symbol value immutably holds an associated value called [[Description]] that is either undefined or a String value.
6.1.5.1 Well-Known SymbolsWell-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless otherwise specified, well-known symbols values are shared by all realms ( 9.3 ).
Within this specification a well-known symbol is referred to using the standard intrinsic notation where the intrinsic is one of the values listed in Table 1 .
NotePrevious editions of this specification used a notation of the form @@name, where the current edition would use %Symbol.name%
. In particular, the following names were used: @@asyncIterator, @@hasInstance, @@isConcatSpreadable, @@ iterator , @@match, @@matchAll, @@replace, @@search, @@species, @@split, @@toPrimitive, @@toStringTag, and @@unscopables.
for
-await
-of
statement. %Symbol.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
operator. %Symbol.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
. %Symbol.iterator% "Symbol.iterator" A method that returns the default iterator for an object. Called by the semantics of the for-of statement. %Symbol.match% "Symbol.match" A regular expression method that matches the regular expression against a string. Called by the String.prototype.match
method. %Symbol.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
method. %Symbol.replace% "Symbol.replace" A regular expression method that replaces matched substrings of a string. Called by the String.prototype.replace
method. %Symbol.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
method. %Symbol.species% "Symbol.species" A function valued property that is the constructor function that is used to create derived objects. %Symbol.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
method. %Symbol.toPrimitive% "Symbol.toPrimitive" A method that converts an object to a corresponding primitive value. Called by the ToPrimitive abstract operation. %Symbol.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
. %Symbol.unscopables% "Symbol.unscopables" An object valued property whose own and inherited property names are property names that are excluded from the with
environment bindings of the associated object. 6.1.6 Numeric Types
ECMAScript has two built-in numeric types: Number and BigInt. The following abstract operations are defined over these numeric types. 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 Operation Example source Invoked by the Evaluation semantics of ... Result Number::unaryMinus-x
Unary -
Operator Number BigInt::unaryMinus BigInt Number::bitwiseNOT ~x
Bitwise NOT Operator ( ~
) Number BigInt::bitwiseNOT BigInt Number::exponentiate x ** y
Exponentiation Operator and Math.pow ( base, exponent ) Number BigInt::exponentiate either a normal completion containing a BigInt or a throw completion Number::multiply x * y
Multiplicative Operators Number BigInt::multiply BigInt Number::divide x / y
Multiplicative Operators Number BigInt::divide either a normal completion containing a BigInt or a throw completion Number::remainder x % y
Multiplicative Operators Number BigInt::remainder either a normal completion containing a BigInt or a throw completion Number::add x ++
++ x
x + y
Postfix Increment Operator , Prefix Increment Operator , and The Addition Operator ( +
) Number BigInt::add BigInt Number::subtract x --
-- x
x - y
Postfix Decrement Operator , Prefix Decrement Operator , and The Subtraction Operator ( -
) Number BigInt::subtract BigInt Number::leftShift x << y
The Left Shift Operator ( <<
) Number BigInt::leftShift BigInt Number::signedRightShift x >> y
The Signed Right Shift Operator ( >>
) Number BigInt::signedRightShift BigInt Number::unsignedRightShift x >>> y
The Unsigned Right Shift Operator ( >>>
) Number BigInt::unsignedRightShift a throw completion Number::lessThan x < y
x > y
x <= y
x >= y
Relational Operators , via IsLessThan ( x, y, LeftFirst ) Boolean or undefined (for unordered inputs) BigInt::lessThan Boolean Number::equal x == y
x != y
x === y
x !== y
Equality Operators , via IsStrictlyEqual ( x, y ) Boolean BigInt::equal Number::sameValue Object.is(x, y)
Object internal methods, via SameValue ( x, y ) , to test exact value equality Boolean Number::sameValueZero [x].includes(y)
via SameValueZero ( x, y ) , to test value equality, ignoring the difference between +0 𝔽 and -0 𝔽, as in Array, Map, and Set methods Boolean Number::bitwiseAND x & y
Binary Bitwise Operators Number BigInt::bitwiseAND BigInt Number::bitwiseXOR x ^ y
Number BigInt::bitwiseXOR BigInt Number::bitwiseOR x | y
Number BigInt::bitwiseOR BigInt Number::toString String(x)
Many expressions and built-in functions, via ToString ( argument ) String BigInt::toString
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
and BigInt
functions to convert among types when calling a function which requires another type.
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.
6.1.6.1 The Number TypeThe Number type has exactly 18,437,736,874,454,810,627 (that is, 2 64 - 2 53 + 3 ) values, representing the double-precision floating point IEEE 754-2019 binary64 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 NaN 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
.) In some implementations, external code might be able to detect a difference between various NaN values, but such behaviour is implementation-defined ; to ECMAScript code, all NaN values are indistinguishable from each other.
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.
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
(or simply Infinity
) and -Infinity
.)
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
(or simply 0
) and -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 × 2e
where s is 1 or -1, m is an integer in the interval from 252 (inclusive) to 253 (exclusive), and e is an integer in the inclusive interval from -1074 to 971.
The remaining 9,007,199,254,740,990 (that is, 2 53 - 2 ) values are denormalized, having the form
s × m × 2e
where s is 1 or -1, m is an integer in the interval from 0 (exclusive) to 252 (exclusive), and e is -1074.
Note that all the positive and negative integers whose magnitude is no greater than 253 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 21024 (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 21024 and -2 1024 are considered to have even significands. Finally, if 21024 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 the inclusive interval from -2 31 to 2 31 - 1 or the inclusive interval from 0 to 2 16 - 1 . 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 .
6.1.6.1.1 Number::unaryMinus ( x )The abstract operation Number::unaryMinus takes argument x (a Number) and returns a Number. It performs the following steps when called:
The abstract operation Number::bitwiseNOT takes argument x (a Number) and returns an integral Number . It performs the following steps when called:
The abstract operation Number::exponentiate takes arguments base (a Number) and exponent (a Number) and returns 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:
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 revisions of IEEE 754 specified 1 𝔽. The historical ECMAScript behaviour is preserved for compatibility reasons.
The abstract operation Number::multiply takes arguments x (a Number) and y (a Number) and returns 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:
Finite -precision multiplication is commutative, but not always associative.
6.1.6.1.5 Number::divide ( x, y )The abstract operation Number::divide takes arguments x (a Number) and y (a Number) and returns 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:
The abstract operation Number::remainder takes arguments n (a Number) and d (a Number) and returns 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:
In C and C++, the remainder operator accepts only integral operands; in ECMAScript, it also accepts floating-point operands.
Note 2The 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
integerremainder operator. Instead the ECMAScript language defines
%
on floating-point operations to behave in a manner analogous to that of the Java
integerremainder operator; this may be compared with the C library function fmod.
6.1.6.1.7 Number::add ( x, y )The abstract operation Number::add takes arguments x (a Number) and y (a Number) and returns 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:
Finite -precision addition is commutative, but not always associative.
6.1.6.1.8 Number::subtract ( x, y )The abstract operation Number::subtract takes arguments x (a Number) and y (a Number) and returns 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:
It is always the case that x - y
produces the same result as x + (-y)
.
The abstract operation Number::leftShift takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
The abstract operation Number::signedRightShift takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
The abstract operation Number::unsignedRightShift takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
The abstract operation Number::lessThan takes arguments x (a Number) and y (a Number) and returns a Boolean or undefined . It performs the following steps when called:
The abstract operation Number::equal takes arguments x (a Number) and y (a Number) and returns a Boolean. It performs the following steps when called:
The abstract operation Number::sameValue takes arguments x (a Number) and y (a Number) and returns a Boolean. It performs the following steps when called:
The abstract operation Number::sameValueZero takes arguments x (a Number) and y (a Number) and returns a Boolean. It performs the following steps when called:
The abstract operation NumberBitwiseOp takes arguments op (&
, ^
, or |
), x (a Number), and y (a Number) and returns an integral Number . It performs the following steps when called:
&
, then
^
, then
|
.The abstract operation Number::bitwiseAND takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
&
, x, y).The abstract operation Number::bitwiseXOR takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
^
, x, y).The abstract operation Number::bitwiseOR takes arguments x (a Number) and y (a Number) and returns an integral Number . It performs the following steps when called:
|
, x, y).The abstract operation Number::toString takes arguments x (a Number) and radix (an integer in the inclusive interval from 2 to 36) and returns a String. It represents x as a String using a positional numeral system with radix radix. The digits used in the representation of a number using radix r are taken from the first r code units of "0123456789abcdefghijklmnopqrstuvwxyz" in order. The representation of numbers with magnitude greater than or equal to 1 𝔽 never includes leading zeroes. It performs the following steps when called:
1.2e+3
.The following observations may be useful as guidelines for implementations, but are not part of the normative requirements of this Standard:
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:
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
https://ampl.com/_archive/first-website/REFS/rounding.pdf. 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
mirror sites.
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.
6.1.6.2.1 BigInt::unaryMinus ( x )The abstract operation BigInt::unaryMinus takes argument x (a BigInt) and returns a BigInt. It performs the following steps when called:
The abstract operation BigInt::bitwiseNOT takes argument x (a BigInt) and returns a BigInt. It returns the one's complement of x. It performs the following steps when called:
The abstract operation BigInt::exponentiate takes arguments base (a BigInt) and exponent (a BigInt) and returns either a normal completion containing a BigInt or a throw completion . It performs the following steps when called:
The abstract operation BigInt::multiply takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
Even if the result has a much larger bit width than the input, the exact mathematical answer is given.
6.1.6.2.5 BigInt::divide ( x, y )The abstract operation BigInt::divide takes arguments x (a BigInt) and y (a BigInt) and returns either a normal completion containing a BigInt or a throw completion . It performs the following steps when called:
The abstract operation BigInt::remainder takes arguments n (a BigInt) and d (a BigInt) and returns either a normal completion containing a BigInt or a throw completion . It performs the following steps when called:
The sign of the result is the sign of the dividend.
6.1.6.2.7 BigInt::add ( x, y )The abstract operation BigInt::add takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
The abstract operation BigInt::subtract takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
The abstract operation BigInt::leftShift takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
NoteSemantics 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.10 BigInt::signedRightShift ( x, y )The abstract operation BigInt::signedRightShift takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
The abstract operation BigInt::unsignedRightShift takes arguments x (a BigInt) and y (a BigInt) and returns a throw completion . It performs the following steps when called:
The abstract operation BigInt::lessThan takes arguments x (a BigInt) and y (a BigInt) and returns a Boolean. It performs the following steps when called:
6.1.6.2.13 BigInt::equal ( x, y )The abstract operation BigInt::equal takes arguments x (a BigInt) and y (a BigInt) and returns a Boolean. It performs the following steps when called:
6.1.6.2.14 BinaryAnd ( x, y )The abstract operation BinaryAnd takes arguments x (0 or 1) and y (0 or 1) and returns 0 or 1. It performs the following steps when called:
The abstract operation BinaryOr takes arguments x (0 or 1) and y (0 or 1) and returns 0 or 1. It performs the following steps when called:
The abstract operation BinaryXor takes arguments x (0 or 1) and y (0 or 1) and returns 0 or 1. It performs the following steps when called:
The abstract operation BigIntBitwiseOp takes arguments op (&
, ^
, or |
), x (a BigInt), and y (a BigInt) and returns a BigInt. It performs the following steps when called:
&
, then
|
, then
The abstract operation BigInt::bitwiseAND takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
&
, x, y).The abstract operation BigInt::bitwiseXOR takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
^
, x, y).The abstract operation BigInt::bitwiseOR takes arguments x (a BigInt) and y (a BigInt) and returns a BigInt. It performs the following steps when called:
|
, x, y).The abstract operation BigInt::toString takes arguments x (a BigInt) and radix (an integer in the inclusive interval from 2 to 36) and returns a String. It represents x as a String using a positional numeral system with radix radix. The digits used in the representation of a BigInt using radix r are taken from the first r code units of "0123456789abcdefghijklmnopqrstuvwxyz" in order. The representation of BigInts other than 0 ℤ never includes leading zeroes. It performs the following steps when called:
Each instance of the Object type, also referred to simply as “an Object”, represents a collection of properties. Each property is either a data property, or an accessor property:
The properties of an object are uniquely identified using property keys . A property key is either a String or a Symbol. All Strings and Symbols, including the empty String, are valid as property keys . A property name is a property key that is a String .
An integer index is a property name n such that CanonicalNumericIndexString (n) returns an integral Number in the inclusive interval from +0 𝔽 to 𝔽 (253 - 1). An array index is an integer index n such that CanonicalNumericIndexString (n) returns an integral Number in the inclusive interval from +0 𝔽 to 𝔽 (232 - 2).
NoteEvery non-negative safe integer has a corresponding integer index . Every 32-bit unsigned integer except 2 32 - 1 has a corresponding array index . "-0" is neither an integer index nor an array index .
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.
In addition, some objects are callable; these are referred to as functions or function objects and are described further below. All functions in ECMAScript are members of the Object type.
6.1.7.1 Property AttributesAttributes are used in this specification to define and explain the state of Object properties as described in Table 3 . Unless specified explicitly, the initial value of each attribute is its Default Value.
Table 3: Attributes of an Object property Attribute Name Types of property for which it is present Value Domain Default Value Description [[Value]] data property an ECMAScript language value undefined The value retrieved by a get access of the property. [[Writable]] data property a Boolean false If false , attempts by ECMAScript code to change the property's [[Value]] attribute using [[Set]] will not succeed. [[Get]] accessor property an Object or undefined undefined If the value is an Object it must be a function object . The function's [[Call]] internal method ( Table 5 ) is called with an empty arguments list to retrieve the property value each time a get access of the property is performed. [[Set]] accessor property an Object or undefined undefined If the value is an Object it must be a function object . The function's [[Call]] internal method ( Table 5 ) is called with an arguments list containing the assigned value as its sole argument each time a set access of the property is performed. The effect of a property's [[Set]] internal method may, but is not required to, have an effect on the value returned by subsequent calls to the property's [[Get]] internal method. [[Enumerable]] data property or accessor property a Boolean false If true , the property will be enumerated by a for-in enumeration (see 14.7.5 ). Otherwise, the property is said to be non-enumerable. [[Configurable]] data property or accessor property a Boolean false If false , attempts to delete the property, change it from a data property to an accessor property or from an accessor property to a data property , or make any changes to its attributes (other than replacing an existing [[Value]] or setting [[Writable]] to false ) will fail. 6.1.7.2 Object Internal Methods and Internal SlotsThe actual semantics of objects, in ECMAScript, are specified via algorithms called internal methods. Each object in an ECMAScript engine is associated with a set of internal methods that defines its runtime behaviour. These internal methods are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. However, each object within an implementation of ECMAScript must behave as specified by the internal methods associated with it. The exact manner in which this is accomplished is determined by the implementation.
Internal method names are polymorphic. This means that different object values may perform different algorithms when a common internal method name is invoked upon them. That actual object upon which an internal method is invoked is the “target” of the invocation. If, at runtime, the implementation of an algorithm attempts to use an internal method of an object that the object does not support, a TypeError exception is thrown.
Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific internal slot specification, such state may consist of values of any ECMAScript language type or of specific ECMAScript specification type values. Unless explicitly specified otherwise, internal slots are allocated as part of the process of creating an object and may not be dynamically added to an object. Unless specified otherwise, the initial value of an internal slot is the value undefined . Various algorithms within this specification create objects that have internal slots. However, the ECMAScript language provides no direct way to associate internal slots with an object.
All objects have an internal slot named [[PrivateElements]], which is a List of PrivateElements . This List represents the values of the private fields, methods, and accessors for the object. Initially, it is an empty List .
Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[ ]].
Table 4 summarizes the essential internal methods used by this specification that are applicable to all objects created or manipulated by ECMAScript code. Every object must have algorithms for all of the essential internal methods. However, all objects do not necessarily use the same algorithms for those methods.
An ordinary object is an object that satisfies all of the following criteria:
An exotic object is an object that is not an ordinary object .
This specification recognizes different kinds of exotic objects by those objects' internal methods. An object that is behaviourally equivalent to a particular kind of exotic object (such as an Array exotic object or a bound function exotic object ), but does not have the same collection of internal methods specified for that kind, is not recognized as that kind of exotic object .
The “Signature” column of Table 4 and other similar tables describes the invocation pattern for each internal method. The invocation pattern always includes a parenthesized list of descriptive parameter names. If a parameter name is the same as an ECMAScript type name then the name describes the required type of the parameter value. If an internal method explicitly returns a value, its parameter list is followed by the symbol “→” and the type name of the returned value. The type names used in signatures refer to the types defined in clause 6 augmented by the following additional names. “any” means the value may be any ECMAScript language type .
In addition to its parameters, an internal method always has access to the object that is the target of the method invocation.
An internal method implicitly returns a Completion Record , either a normal completion that wraps a value of the return type shown in its invocation pattern, or a throw completion .
Table 4: Essential Internal Methods Internal Method Signature Description [[GetPrototypeOf]] ( ) → Object | Null Determine the object that provides inherited properties for this object. A null value indicates that there are no inherited properties. [[SetPrototypeOf]] (Object | Null) → Boolean Associate this object with another object that provides inherited properties. Passing null indicates that there are no inherited properties. Returns true indicating that the operation was completed successfully or false indicating that the operation was not successful. [[IsExtensible]] ( ) → Boolean Determine whether it is permitted to add additional properties to this object. [[PreventExtensions]] ( ) → Boolean Control whether new properties may be added to this object. Returns true if the operation was successful or false if the operation was unsuccessful. [[GetOwnProperty]] (propertyKey) → Undefined | Property Descriptor Return a Property Descriptor for the own property of this object whose key is propertyKey, or undefined if no such property exists. [[DefineOwnProperty]] (propertyKey, PropertyDescriptor) → Boolean Create or alter the own property, whose key is propertyKey, to have the state described by PropertyDescriptor. Return true if that property was successfully created/updated or false if the property could not be created or updated. [[HasProperty]] (propertyKey) → Boolean Return a Boolean value indicating whether this object already has either an own or inherited property whose key is propertyKey. [[Get]] (propertyKey, Receiver) → any Return the value of the property whose key is propertyKey from this object. If any ECMAScript code must be executed to retrieve the property value, Receiver is used as the this value when evaluating the code. [[Set]] (propertyKey, value, Receiver) → Boolean Set the value of the property whose key is propertyKey to value. If any ECMAScript code must be executed to set the property value, Receiver is used as the this value when evaluating the code. Returns true if the property value was set or false if it could not be set. [[Delete]] (propertyKey) → Boolean Remove the own property whose key is propertyKey from this object. Return false if the property was not deleted and is still present. Return true if the property was deleted or is not present. [[OwnPropertyKeys]] ( ) → List of property keys Return a List whose elements are all of the own property keys for the object.Table 5 summarizes additional essential internal methods that are supported by objects that may be called as functions. A function object is an object that supports the [[Call]] internal method. A constructor is an object that supports the [[Construct]] internal method. Every object that supports [[Construct]] must support [[Call]]; that is, every constructor must be a function object . Therefore, a constructor may also be referred to as a constructor function or constructor function object .
Table 5: Additional Essential Internal Methods of Function Objects Internal Method Signature Description [[Call]] (any, a List of any) → any Executes code associated with this object. Invoked via a function call expression. The arguments to the internal method are a this value and a List whose elements are the arguments passed to the function by a call expression. Objects that implement this internal method are callable. [[Construct]] (a List of any, Object) → Object Creates an object. Invoked via thenew
operator or a super
call. The first argument to the internal method is a List whose elements are the arguments of the constructor invocation or the super
call. The second argument is the object to which the new
operator was initially applied. Objects that implement this internal method are called constructors . A function object is not necessarily a constructor and such non- constructor function objects do not have a [[Construct]] internal method.
The semantics of the essential internal methods for ordinary objects and standard exotic objects are specified in clause 10 . If any specified use of an internal method of an exotic object is not supported by an implementation, that usage must throw a TypeError exception when attempted.
6.1.7.3 Invariants of the Essential Internal MethodsThe Internal Methods of Objects of an ECMAScript engine must conform to the list of invariants specified below. Ordinary ECMAScript Objects as well as all standard exotic objects in this specification maintain these invariants. ECMAScript Proxy objects maintain these invariants by means of runtime checks on the result of traps invoked on the [[ProxyHandler]] object.
Any implementation provided exotic objects must also maintain these invariants for those objects. Violation of these invariants may cause ECMAScript code to have unpredictable behaviour and create security issues. However, violation of these invariants must never compromise the memory safety of an implementation.
An implementation must not allow these invariants to be circumvented in any manner such as by providing alternative interfaces that implement the functionality of the essential internal methods without enforcing their invariants.
Definitions:The value returned by any internal method must be a Completion Record with either:
An internal method must not return a continue completion , a break completion , or a return completion .
[[GetPrototypeOf]] ( )An object's prototype chain should have finite length (that is, starting from any object, recursively applying the [[GetPrototypeOf]] internal method to its result should eventually lead to the value null ). However, this requirement is not enforceable as an object level invariant if the prototype chain includes any exotic objects that do not use the ordinary object definition of [[GetPrototypeOf]]. Such a circular prototype chain may result in infinite loops when accessing object properties.
[[SetPrototypeOf]] ( V )As a consequence of the third invariant, if a property is described as a data property and it may return different values over time, then either or both of the [[Writable]] and [[Configurable]] attributes must be true even if no mechanism to change the value is exposed via the other essential internal methods.
[[DefineOwnProperty]] ( P, Desc )Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have realm -specific identities. Unless otherwise specified each intrinsic object actually corresponds to a set of similar objects, one per realm .
Within this specification a reference such as %name% means the intrinsic object, associated with the current realm , corresponding to the name. A reference such as %name.a.b% means, as if the "b" property of the value of the "a" property of the intrinsic object %name% was accessed prior to any ECMAScript code being evaluated. Determination of the current realm and its intrinsics is described in 9.4 . The well-known intrinsics are listed in Table 6 .
Table 6: Well-Known Intrinsic Objects NoteAdditional entries in Table 102 .
6.2 ECMAScript Specification TypesA specification type corresponds to meta-values that are used within algorithms to describe the semantics of ECMAScript language constructs and ECMAScript language types . The specification types include Reference Record , List , Completion Record , Property Descriptor , Environment Record , Abstract Closure , and Data Block . Specification type values are specification artefacts that do not necessarily correspond to any specific entity within an ECMAScript implementation. Specification type values may be used to describe intermediate results of ECMAScript expression evaluation but such values cannot be stored as properties of objects or values of ECMAScript language variables.
6.2.1 The Enum Specification TypeEnums are values which are internal to the specification and not directly observable from ECMAScript code. Enums are denoted using a sans-serif typeface. For instance, a Completion Record 's [[Type]] field takes on values like normal , return , or throw . Enums have no characteristics other than their name. The name of an enum serves no purpose other than to distinguish it from other enums, and implies nothing about its usage or meaning in context.
6.2.2 The List and Record Specification TypesThe List type is used to explain the evaluation of argument lists (see 13.3.8 ) in new
expressions, in function calls, and in other algorithms where a simple ordered list of values is needed. Values of the List type are simply ordered sequences of list elements containing the individual values. These sequences may be of any length. The elements of a list may be randomly accessed using 0-origin indices. For notational convenience an array-like syntax can be used to access List elements. For example, arguments[2] is shorthand for saying the 3rd element of the List arguments.
When an algorithm iterates over the elements of a List without specifying an order, the order used is the order of the elements in the List.
For notational convenience within this specification, a literal syntax can be used to express a new List value. For example, « 1, 2 » defines a List value that has two elements each of which is initialized to a specific value. A new empty List can be expressed as « ».
In this specification, the phrase "the list-concatenation of A, B, ..." (where each argument is a possibly empty List) denotes a new List value whose elements are the concatenation of the elements (in order) of each of the arguments (in order).
As applied to a List of Strings, the phrase "sorted according to lexicographic code unit order" means sorting by the numeric value of each code unit up to the length of the shorter string, and sorting the shorter string before the longer string if all are equal, as described in the abstract operation IsLessThan .
The Record type is used to describe data aggregations within the algorithms of this specification. A Record type value consists of one or more named fields. The value of each field is an ECMAScript language value or specification value. Field names are always enclosed in double brackets, for example [[Value]].
For notational convenience within this specification, an object literal-like syntax can be used to express a Record value. For example, { [[Field1]]: 42, [[Field2]]: false , [[Field3]]: empty } defines a Record value that has three fields, each of which is initialized to a specific value. Field name order is not significant. Any fields that are not explicitly listed are considered to be absent.
In specification text and algorithms, dot notation may be used to refer to a specific field of a Record value. For example, if R is the record shown in the previous paragraph then R.[[Field2]] is shorthand for “the field of R named [[Field2]]”.
Schema for commonly used Record field combinations may be named, and that name may be used as a prefix to a literal Record value to identify the specific kind of aggregations that is being described. For example: PropertyDescriptor { [[Value]]: 42, [[Writable]]: false , [[Configurable]]: true }.
6.2.3 The Set and Relation Specification TypesThe Set type is used to explain a collection of unordered elements for use in the memory model . It is distinct from the ECMAScript collection type of the same name. To disambiguate, instances of the ECMAScript collection are consistently referred to as "Set objects" within this specification. Values of the Set type are simple collections of elements, where no element appears more than once. Elements may be added to and removed from Sets. Sets may be unioned, intersected, or subtracted from each other.
The Relation type is used to explain constraints on Sets. Values of the Relation type are Sets of ordered pairs of values from its value domain. For example, a Relation on events is a set of ordered pairs of events. For a Relation R and two values a and b in the value domain of R, a R b is shorthand for saying the ordered pair (a, b) is a member of R. A Relation is the least Relation with respect to some conditions when it is the smallest Relation that satisfies those conditions.
A strict partial order is a Relation value R that satisfies the following.
For all a, b, and c in R's domain:
The two properties above are called irreflexivity and transitivity, respectively.
A strict total order is a Relation value R that satisfies the following.
For all a, b, and c in R's domain:
The three properties above are called totality, irreflexivity, and transitivity, respectively.
6.2.4 The Completion Record Specification TypeThe Completion Record specification type is used to explain the runtime propagation of values and control flow such as the behaviour of statements (break
, continue
, return
and throw
) that perform nonlocal transfers of control.
Completion Records have the fields defined in Table 7 .
Table 7: Completion Record Fields Field Name Value Meaning [[Type]] normal , break , continue , return , or throw The type of completion that occurred. [[Value]] any value except a Completion Record The value that was produced. [[Target]] a String or empty The target label for directed control transfers.The following shorthand terms are sometimes used to refer to Completion Records.
Callable objects that are defined in this specification only return a normal completion or a throw completion. Returning any other kind of Completion Record is considered an editorial error.
Implementation-defined callable objects must return either a normal completion or a throw completion.
6.2.4.1 NormalCompletion ( value )The abstract operation NormalCompletion takes argument value (any value except a Completion Record ) and returns a normal completion . It performs the following steps when called:
The abstract operation ThrowCompletion takes argument value (an ECMAScript language value ) and returns a throw completion . It performs the following steps when called:
The abstract operation ReturnCompletion takes argument value (an ECMAScript language value ) and returns a return completion . It performs the following steps when called:
The abstract operation UpdateEmpty takes arguments completionRecord (a Completion Record ) and value (any value except a Completion Record ) and returns a Completion Record . It performs the following steps when called:
The Reference Record type is used to explain the behaviour of such operators as delete
, typeof
, the assignment operators, the super
keyword and other language features. For example, the left-hand operand of an assignment is expected to produce a Reference Record.
A Reference Record is a resolved name or (possibly not-yet-resolved) property binding; its fields are defined by Table 8 .
Table 8: Reference Record FieldsThe following abstract operations are used in this specification to operate upon Reference Records:
6.2.5.1 IsPropertyReference ( V )The abstract operation IsPropertyReference takes argument V (a Reference Record ) and returns a Boolean. It performs the following steps when called:
The abstract operation IsUnresolvableReference takes argument V (a Reference Record ) and returns a Boolean. It performs the following steps when called:
The abstract operation IsSuperReference takes argument V (a Reference Record ) and returns a Boolean. It performs the following steps when called:
The abstract operation IsPrivateReference takes argument V (a Reference Record ) and returns a Boolean. It performs the following steps when called:
The abstract operation GetValue takes argument V (a Reference Record or an ECMAScript language value ) and returns either a normal completion containing an ECMAScript language value or an abrupt completion . It performs the following steps when called:
The object that may be created in step 3.a is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might choose to avoid the actual creation of the object.
6.2.5.6 PutValue ( V, W )The abstract operation PutValue takes arguments V (a Reference Record or an ECMAScript language value ) and W (an ECMAScript language value ) and returns either a normal completion containing unused or an abrupt completion . It performs the following steps when called:
The object that may be created in step 3.a is not accessible outside of the above abstract operation and the ordinary object [[Set]] internal method. An implementation might choose to avoid the actual creation of that object.
6.2.5.7 GetThisValue ( V )The abstract operation GetThisValue takes argument V (a Reference Record ) and returns an ECMAScript language value . It performs the following steps when called:
The abstract operation InitializeReferencedBinding takes arguments V (a Reference Record ) and W (an ECMAScript language value ) and returns either a normal completion containing unused or an abrupt completion . It performs the following steps when called:
The abstract operation MakePrivateReference takes arguments baseValue (an ECMAScript language value ) and privateIdentifier (a String) and returns a Reference Record . It performs the following steps when called:
The Property Descriptor type is used to explain the manipulation and reification of Object property attributes. A Property Descriptor is a Record with zero or more fields, where each field's name is an attribute name and its value is a corresponding attribute value as specified in 6.1.7.1 . The schema name used within this specification to tag literal descriptions of Property Descriptor records is “PropertyDescriptor”.
Property Descriptor values may be further classified as data Property Descriptors and accessor Property Descriptors based upon the existence or use of certain fields. A data Property Descriptor is one that includes any fields named either [[Value]] or [[Writable]]. An accessor Property Descriptor is one that includes any fields named either [[Get]] or [[Set]]. Any Property Descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value may not be both a data Property Descriptor and an accessor Property Descriptor; however, it may be neither (in which case it is a generic Property Descriptor). A fully populated Property Descriptor is one that is either an accessor Property Descriptor or a data Property Descriptor and that has all of the corresponding fields defined in Table 3 .
The following abstract operations are used in this specification to operate upon Property Descriptor values:
6.2.6.1 IsAccessorDescriptor ( Desc )The abstract operation IsAccessorDescriptor takes argument Desc (a Property Descriptor ) and returns a Boolean. It performs the following steps when called:
The abstract operation IsDataDescriptor takes argument Desc (a Property Descriptor ) and returns a Boolean. It performs the following steps when called:
The abstract operation IsGenericDescriptor takes argument Desc (a Property Descriptor ) and returns a Boolean. It performs the following steps when called:
The abstract operation FromPropertyDescriptor takes argument Desc (a Property Descriptor or undefined ) and returns an Object or undefined . It performs the following steps when called:
The abstract operation ToPropertyDescriptor takes argument Obj (an ECMAScript language value ) and returns either a normal completion containing a Property Descriptor or a throw completion . It performs the following steps when called:
The abstract operation CompletePropertyDescriptor takes argument Desc (a Property Descriptor ) and returns unused . It performs the following steps when called:
The Environment Record type is used to explain the behaviour of name resolution in nested functions and blocks. This type and the operations upon it are defined in 9.1 .
6.2.8 The Abstract Closure Specification TypeThe Abstract Closure specification type is used to refer to algorithm steps together with a collection of values. Abstract Closures are meta-values and are invoked using function application style such as closure(arg1, arg2). Like abstract operations , invocations perform the algorithm steps described by the Abstract Closure.
In algorithm steps that create an Abstract Closure, values are captured with the verb "capture" followed by a list of aliases. When an Abstract Closure is created, it captures the value that is associated with each alias at that time. In steps that specify the algorithm to be performed when an Abstract Closure is called, each captured value is referred to by the alias that was used to capture the value.
If an Abstract Closure returns a Completion Record , that Completion Record must be either a normal completion or a throw completion .
Abstract Closures are created inline as part of other algorithms, shown in the following example.
The Data Block specification type is used to describe a distinct and mutable sequence of byte-sized (8 bit) numeric values. A byte value is an integer in the inclusive interval from 0 to 255. A Data Block value is created with a fixed number of bytes that each have the initial value 0.
For notational convenience within this specification, an array-like syntax can be used to access the individual bytes of a Data Block value. This notation presents a Data Block value as a 0-based integer-indexed sequence of bytes. For example, if db is a 5 byte Data Block value then db[2] can be used to access its 3rd byte.
A data block that resides in memory that can be referenced from multiple agents concurrently is designated a Shared Data Block. A Shared Data Block has an identity (for the purposes of equality testing Shared Data Block values) that is address-free: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.
The semantics of Shared Data Blocks is defined using Shared Data Block events by the memory model . Abstract operations below introduce Shared Data Block events and act as the interface between evaluation semantics and the event semantics of the memory model . The events form a candidate execution , on which the memory model acts as a filter. Please consult the memory model for full semantics.
Shared Data Block events are modelled by Records , defined in the memory model .
The following abstract operations are used in this specification to operate upon Data Block values:
6.2.9.1 CreateByteDataBlock ( size )The abstract operation CreateByteDataBlock takes argument size (a non-negative integer ) and returns either a normal completion containing a Data Block or a throw completion . It performs the following steps when called:
The abstract operation CopyDataBlockBytes takes arguments toBlock (a Data Block or a Shared Data Block ), toIndex (a non-negative integer ), fromBlock (a Data Block or a Shared Data Block ), fromIndex (a non-negative integer ), and count (a non-negative integer ) and returns unused . It performs the following steps when called:
The PrivateElement type is a Record used in the specification of private class fields, methods, and accessors. Although Property Descriptors are not used for private elements, private fields behave similarly to non-configurable, non-enumerable, writable data properties , private methods behave similarly to non-configurable, non-enumerable, non-writable data properties , and private accessors behave similarly to non-configurable, non-enumerable accessor properties .
Values of the PrivateElement type are Record values whose fields are defined by Table 9 . Such values are referred to as PrivateElements.
Table 9: PrivateElement Fields Field Name Values of the [[Kind]] field for which it is present Value Meaning [[Key]] All a Private Name The name of the field, method, or accessor. [[Kind]] All field , method , or accessor The kind of the element. [[Value]] field and method an ECMAScript language value The value of the field. [[Get]] accessor a function object or undefined The getter for a private accessor. [[Set]] accessor a function object or undefined The setter for a private accessor. 6.2.11 The ClassFieldDefinition Record Specification TypeThe ClassFieldDefinition type is a Record used in the specification of class fields.
Values of the ClassFieldDefinition type are Record values whose fields are defined by Table 10 . Such values are referred to as ClassFieldDefinition Records.
Table 10: ClassFieldDefinition Record Fields Field Name Value Meaning [[Name]] a Private Name , a String, or a Symbol The name of the field. [[Initializer]] an ECMAScript function object or empty The initializer of the field, if any. 6.2.12 Private NamesThe Private Name specification type is used to describe a globally unique value (one which differs from any other Private Name, even if they are otherwise indistinguishable) which represents the key of a private class element (field, method, or accessor). Each Private Name has an associated immutable [[Description]] which is a String value. A Private Name may be installed on any ECMAScript object with PrivateFieldAdd or PrivateMethodOrAccessorAdd , and then read or written using PrivateGet and PrivateSet .
6.2.13 The ClassStaticBlockDefinition Record Specification TypeA ClassStaticBlockDefinition Record is a Record value used to encapsulate the executable code for a class static initialization block.
ClassStaticBlockDefinition Records have the fields listed in Table 11 .
Table 11: ClassStaticBlockDefinition Record FieldsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3