But this code runs successfully:
+0n throws an error but
-0n does not?
So that it doesn't break asm.js:
+followed by an expression is always either a Number, or results in throwing. For this reason, unfortunately,
+on a BigInt needs to throw, rather than being symmetrical with
+on Number: Otherwise, previously "type-declared" asm.js code would now be polymorphic.
As Bergi highlights in the comments, this was the least bad of three options:
+BigInt -> BigInt: breaks asm.js, and anything else that made the assumption "unary plus gives a Number";
+BigInt -> Number: conflicts with the design decision to disallow implicit conversions between Number and BigInt; or
+BigInt -> error.
+0n is treated as
+(BigInt(0)), since unary
+ means "cast to integer", and it can't automatically do that (for some reason)
-0n is treated as
BigInt(-0), since negative numbers can be big integers
(You need to check your console for this, since I guess there's a bug in the StackSnippets preventing BigInts from being casted to a string in the