A has an associated type which is one of: number, date, string, binary, or array.
A key also has an associated value, which will be either: an if type is number or date, a if type is string, a if type is binary, or a list of other if type is array.
An ECMAScript [ECMA-262] value can be converted to a by following the steps to convert a value to a key.
The following ECMAScript types are valid keys:
primitive values, except NaN. This includes Infinity and -Infinity.
Date objects, except where the [[DateValue]] internal slot is NaN.
primitive values.
ArrayBuffer objects (or views on buffers such as ).
Array objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself. This includes empty arrays. Arrays can contain other arrays.
Attempting to convert other ECMAScript values to a will fail.
An array key is a key with array. The subkeys of an array key are the of the array key‘s .
Let ta be the type of a.
Let tb be the of b.
Let va be the value of a.
Let vb be the of b.
Switch on ta:
number
date
If va is greater than vb, then return 1.
If va is less than vb, then return -1.
Return 0.
The key a is greater than the b if the result of running compare two keys with a and b is 1.
The a is less than the key b if the result of running with a and b is -1.
The key a is equal to the b if the result of running compare two keys with a and b is 0.
Members of binary keys are compared as unsigned values (in the range 0 to 255 inclusive) rather than signed values (in the range -128 to 127 inclusive).