5 ms·
So, you can add a string to a BigInt, but not a Number? Their 'explanation' for not allowing Number and BigInt to be mixed is that you could lose precision. Not
by gcbirzan 8y ago
So, you can add a string to a BigInt, but not a Number? Their 'explanation' for not allowing Number and BigInt to be mixed is that you could lose precision. Not if you return a BigInt.
- deleted 8y ago[deleted]
- maxxxxx 8y agoThat seems a pretty odd choice in both cases. Adding a number to BigInt should return a BigInt. I am also always wary of languages that allow mixing of strings and numbers. From my experience this can cause a lot of problems.
- gcbirzan 8y agoIt's hilarious, because: "1" + 1 === "11" "1" - 1 === 0 "1" + 1n === "11" "1" - 1n: Exception
- maxxxxx 8y agoOur testers write a lot scripts in PHP and I have spent countless hours debugging stuff like this. A special kind of fun is to figure out what expressions count as TRUE or FALSE. JavaScript seems to have the same, slightly different, problems.