as far as i am aware, ToPrimitive does not throw an error for any builtin JavaScript object type
but you can make your own objects which throw errors by defining [Symbol.toPrimitive]() on them
anyway + fails if :—
1. ToPrimitive throws an error, for example because it does not produce a primitive
2. one of the resulting primitive values is a string, and ToString throws an error, because the primitive value cannot be converted to a string (symbols are the only primitive value which can’t be converted to strings by ToString atm)
3. neither primitive value is a string, and ToNumeric throws an error, for example because it does not produce a numeric value
4. The numeric values produced by calling ToNumeric on both sides are different types (presently the available types are numbers and bigints)
for the people who aren’t up on the ECMAScript standard, ToPrimitive, ToString, and ToNumeric are abstract operations defined in the standard, not functions callable from within Javascript code
compare
({ false: "good", true: "bad" }[{
toString () { return "false" },
valueOf () { return true },
}])
Administrator / Public Relations for GlitchCat. Not actually glitchy, nor a cat. I wrote the rules for this instance.
“Constitutionally incapable of not going hard” — @aescling
“Fedi Cassandra” – @Satsuma
I HAVE EXPERIENCE IN THINGS. YOU CAN JUST @ ME.
I work for a library but I post about Zelda fanfiction.