7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible takes argument argument (an
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 (an
- If argument
is not an Object , returnfalse . - If argument is an
Array exotic object , returntrue . - If argument is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (argument). - Let proxyTarget be argument.[[ProxyTarget]].
- Return ?
IsArray (proxyTarget).
- Perform ?
- Return
false .
7.2.3 IsCallable ( argument )
The abstract operation IsCallable takes argument argument (an
- If argument
is not an 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 argument
is not an 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 either a
- Return ? O.[[IsExtensible]]().
7.2.6 IsIntegralNumber ( argument )
The abstract operation IsIntegralNumber takes argument argument (an
- If argument
is not a Number , returnfalse . - If argument is not
finite , returnfalse . - If
truncate (ℝ (argument)) ≠ℝ (argument), returnfalse . - Return
true .
7.2.7 IsPropertyKey ( argument )
The abstract operation IsPropertyKey takes argument argument (an
- If argument
is a String , returntrue . - If argument
is a Symbol , returntrue . - Return
false .
7.2.8 IsRegExp ( argument )
The abstract operation IsRegExp takes argument argument (an
- If argument
is not an Object , returnfalse . - Let matcher be ?
Get (argument,@@match ). - If matcher is not
undefined , returnToBoolean (matcher). - If argument has a [[RegExpMatcher]] internal slot, return
true . - Return
false .
7.2.9 Static Semantics: IsStringWellFormedUnicode ( string )
The abstract operation IsStringWellFormedUnicode takes argument string (a String) and returns a Boolean. It interprets string as a sequence of UTF-16 encoded code points, as described in
- Let len be the length of string.
- Let k be 0.
- Repeat, while k < len,
- Let cp be
CodePointAt (string, k). - If cp.[[IsUnpairedSurrogate]] is
true , returnfalse . - Set k to k + cp.[[CodeUnitCount]].
- Let cp be
- Return
true .
7.2.10 SameValue ( x, y )
The abstract operation SameValue takes arguments x (an
- If
Type (x) is notType (y), returnfalse . - If x
is a Number , then- Return
Number::sameValue (x, y).
- Return
- Return
SameValueNonNumber (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 notType (y), returnfalse . - If x
is a Number , then- Return
Number::sameValueZero (x, y).
- Return
- Return
SameValueNonNumber (x, y).
SameValueZero differs from
7.2.12 SameValueNonNumber ( x, y )
The abstract operation SameValueNonNumber takes arguments x (an
Assert :Type (x) isType (y).- If x is either
null orundefined , returntrue . - If x
is a BigInt , then- Return
BigInt::equal (x, y).
- Return
- If x
is a String , then- If x and y have the same length and the same code units in the same positions, return
true ; otherwise, returnfalse .
- If x and y have the same length and the same code units in the same positions, return
- If x
is a Boolean , then- If x and y are both
true or bothfalse , returntrue ; otherwise, returnfalse .
- If x and y are both
- NOTE: All other
ECMAScript language values are compared by identity. - If x is y, return
true ; otherwise, returnfalse .
7.2.13 IsLessThan ( x, y, LeftFirst )
The abstract operation IsLessThan takes arguments x (an
- If LeftFirst 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 px
is a String and pyis a String , then- Let lx be the length of px.
- Let ly be the length of py.
- For each
integer i such that 0 ≤ i <min (lx, ly), in ascending order, do- Let cx be the numeric value of the code unit at index i within px.
- Let cy be the numeric value of the code unit at index i within py.
- If cx < cy, return
true . - If cx > cy, return
false .
- If lx < ly, return
true . Otherwise, returnfalse .
- Else,
- If px
is a BigInt and pyis a String , then- Let ny be
StringToBigInt (py). - If ny is
undefined , returnundefined . - Return
BigInt::lessThan (px, ny).
- Let ny be
- If px
is a String and pyis a BigInt , then- Let nx be
StringToBigInt (px). - If nx is
undefined , 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) isType (ny), then- If nx
is a Number , then- Return
Number::lessThan (nx, ny).
- Return
- Else,
Assert : nxis a BigInt .- Return
BigInt::lessThan (nx, ny).
- If nx
Assert : nxis a BigInt and nyis a Number , or nxis a Number and nyis a 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 px
The comparison of Strings uses a simple lexicographic ordering on sequences of UTF-16 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 but not in the same normalization form could test as unequal. Also note that lexicographic ordering by code unit differs from ordering by code point for Strings containing
7.2.14 IsLooselyEqual ( x, y )
The abstract operation IsLooselyEqual takes arguments x (an ==
operator. It performs the following steps when called:
- If
Type (x) isType (y), then- Return
IsStrictlyEqual (x, y).
- Return
- 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.6.2 . - If x
is a Number and yis a String , return !IsLooselyEqual (x, !ToNumber (y)). - If x
is a String and yis a Number , return !IsLooselyEqual (!ToNumber (x), y). - If x
is a BigInt and yis a String , then- Let n be
StringToBigInt (y). - If n is
undefined , returnfalse . - Return !
IsLooselyEqual (x, n).
- Let n be
- If x
is a String and yis a BigInt , return !IsLooselyEqual (y, x). - If x
is a Boolean , return !IsLooselyEqual (!ToNumber (x), y). - If y
is a Boolean , return !IsLooselyEqual (x, !ToNumber (y)). - If x is either a String, a Number, a BigInt, or a Symbol and y
is an Object , return !IsLooselyEqual (x, ?ToPrimitive (y)). - If x
is an Object and y is either a String, a Number, a BigInt, or a Symbol, return !IsLooselyEqual (?ToPrimitive (x), y). - If x
is a BigInt and yis a Number , or if xis a Number and yis a BigInt , then - Return
false .
7.2.15 IsStrictlyEqual ( x, y )
The abstract operation IsStrictlyEqual takes arguments x (an ===
operator. It performs the following steps when called:
- If
Type (x) is notType (y), returnfalse . - If x
is a Number , then- Return
Number::equal (x, y).
- Return
- Return
SameValueNonNumber (x, y).
This algorithm differs from the