today i learned BigInt(string) first converts the string into the number type and then just invokes BigInt(number)

so that’s lossy, right,

Follow

@aescling what no it doesn’t

(spec text follows)

When BigInt is called with argument value, the following steps are taken:

1. If NewTarget is not undefined, throw a TypeError exception.
2. Let prim be ? ToPrimitive(value, `number`).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
4. Otherwise, return ? ToBigInt(value).

(end spec text)

ToPrimitive(string, `number`) === string since strings are already primitives; that step does nothing

· · Web · 1 · 0 · 0

@aescling in fairness it’s an easy mistake but yeah the second argument to ToPrimitive is just a hint and not a guarantee of the actual return type

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.