7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible takes argument argument. It throws an error if argument is a value that cannot be converted to an Object using
Argument Type | Result |
---|---|
Undefined |
Throw a |
Null |
Throw a |
Boolean | Return argument. |
Number | Return argument. |
String | Return argument. |
Symbol | Return argument. |
BigInt | Return argument. |
Object | Return argument. |
7.2.2 IsArray ( argument )
The abstract operation IsArray takes argument argument. It performs the following steps when called:
- If
Type (argument) is not Object, returnfalse . - If argument is an
Array exotic object , returntrue . - If argument is a
Proxy exotic object , then- If argument.[[ProxyHandler]] is
null , throw aTypeError exception. - Let target be argument.[[ProxyTarget]].
- Return ?
IsArray (target).
- If argument.[[ProxyHandler]] is
- Return
false .
7.2.3 IsCallable ( argument )
The abstract operation IsCallable takes argument argument (an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Call]] internal method, return
true . - Return
false .
7.2.4 IsConstructor ( argument )
The abstract operation IsConstructor takes argument argument (an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Construct]] internal method, return
true . - Return
false .
7.2.5 IsExtensible ( O )
The abstract operation IsExtensible takes argument O (an Object) and returns a completion record which, if its [[Type]] is
7.2.6 IsIntegralNumber ( argument )
The abstract operation IsIntegralNumber takes argument argument. It determines if argument is a finite
7.2.7 IsPropertyKey ( argument )
The abstract operation IsPropertyKey takes argument argument (an
7.2.8 IsRegExp ( argument )
The abstract operation IsRegExp takes argument argument. It performs the following steps when called:
7.2.9 IsStringPrefix ( p, q )
The abstract operation IsStringPrefix takes arguments p (a String) and q (a String). It determines if p is a prefix of q. It performs the following steps when called:
Assert :Type (p) is String.Assert :Type (q) is String.- If q can be the
string-concatenation of p and some other String r, returntrue . Otherwise, returnfalse .
Any String is a prefix of itself, because r may be the empty String.
7.2.10 SameValue ( x, y )
The abstract operation SameValue takes arguments x (an
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::sameValue(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
This algorithm differs from the
7.2.11 SameValueZero ( x, y )
The abstract operation SameValueZero takes arguments x (an
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::sameValueZero(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
SameValueZero differs from
7.2.12 SameValueNonNumeric ( x, y )
The abstract operation SameValueNonNumeric takes arguments x (an
Assert :Type (x) is not Number or BigInt.Assert :Type (x) is the same asType (y).- If
Type (x) is Undefined, returntrue . - If
Type (x) is Null, returntrue . - If
Type (x) is String, then- If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return
true ; otherwise, returnfalse .
- If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return
- If
Type (x) is Boolean, then- If x and y are both
true or bothfalse , returntrue ; otherwise, returnfalse .
- If x and y are both
- If
Type (x) is Symbol, then- If x and y are both the same Symbol value, return
true ; otherwise, returnfalse .
- If x and y are both the same Symbol value, return
- If x and y are the same Object value, return
true . Otherwise, returnfalse .
7.2.13 Abstract Relational Comparison
The comparison x < y, where x and y are values, produces
- If the LeftFirst flag is
true , then- Let px be ?
ToPrimitive (x,number ). - Let py be ?
ToPrimitive (y,number ).
- Let px be ?
- Else,
- NOTE: The order of evaluation needs to be reversed to preserve left to right evaluation.
- Let py be ?
ToPrimitive (y,number ). - Let px be ?
ToPrimitive (x,number ).
- If
Type (px) is String andType (py) is String, then- If
IsStringPrefix (py, px) istrue , returnfalse . - If
IsStringPrefix (px, py) istrue , returntrue . - Let k be the smallest non-negative
integer such that the code unit at index k within px is different from the code unit at index k within py. (There must be such a k, for neither String is a prefix of the other.) - Let m be the
integer that is the numeric value of the code unit at index k within px. - Let n be the
integer that is the numeric value of the code unit at index k within py. - If m < n, return
true . Otherwise, returnfalse .
- If
- Else,
- If
Type (px) is BigInt andType (py) is String, then- Let ny be !
StringToBigInt (py). - If ny is
NaN , returnundefined . - Return BigInt::lessThan(px, ny).
- Let ny be !
- If
Type (px) is String andType (py) is BigInt, then- Let nx be !
StringToBigInt (px). - If nx is
NaN , returnundefined . - Return BigInt::lessThan(nx, py).
- Let nx be !
- NOTE: Because px and py are primitive values, evaluation order is not important.
- Let nx be !
ToNumeric (px). - Let ny be !
ToNumeric (py). - If
Type (nx) is the same asType (ny), returnType (nx)::lessThan(nx, ny). Assert :Type (nx) is BigInt andType (ny) is Number, orType (nx) is Number andType (ny) is BigInt.- If nx or ny is
NaN , returnundefined . - If nx is
-∞ _{𝔽} or ny is+∞ _{𝔽}, returntrue . - If nx is
+∞ _{𝔽} or ny is-∞ _{𝔽}, returnfalse . - If
ℝ (nx) <ℝ (ny), returntrue ; otherwise returnfalse .
- If
The comparison of Strings uses a simple lexicographic ordering on sequences of code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore String values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form. Also, note that for strings containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit values differs from that on sequences of code point values.
7.2.14 Abstract Equality Comparison
The comparison x == y, where x and y are values, produces
- If
Type (x) is the same asType (y), then- Return the result of performing
Strict Equality Comparison x === y.
- Return the result of performing
- If x is
null and y isundefined , returntrue . - If x is
undefined and y isnull , returntrue . - NOTE: This step is replaced in section
B.3.7.2 . - If
Type (x) is Number andType (y) is String, return the result of the comparison x == !ToNumber (y). - If
Type (x) is String andType (y) is Number, return the result of the comparison !ToNumber (x) == y. - If
Type (x) is BigInt andType (y) is String, then- Let n be !
StringToBigInt (y). - If n is
NaN , returnfalse . - Return the result of the comparison x == n.
- Let n be !
- If
Type (x) is String andType (y) is BigInt, return the result of the comparison y == x. - If
Type (x) is Boolean, return the result of the comparison !ToNumber (x) == y. - If
Type (y) is Boolean, return the result of the comparison x == !ToNumber (y). - If
Type (x) is either String, Number, BigInt, or Symbol andType (y) is Object, return the result of the comparison x == ?ToPrimitive (y). - If
Type (x) is Object andType (y) is either String, Number, BigInt, or Symbol, return the result of the comparison ?ToPrimitive (x) == y. - If
Type (x) is BigInt andType (y) is Number, or ifType (x) is Number andType (y) is BigInt, then - Return
false .
7.2.15 Strict Equality Comparison
The comparison x === y, where x and y are values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::equal(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
This algorithm differs from the