Given a BigInt in JS, how do you pute its modulo?
10n % 3 // Uncaught TypeError: can't convert BigInt to number
edit: the difference between this question and the one linked as similar is that this question only pertains to BigInt which is fairly recent.
Given a BigInt in JS, how do you pute its modulo?
10n % 3 // Uncaught TypeError: can't convert BigInt to number
edit: the difference between this question and the one linked as similar is that this question only pertains to BigInt https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt which is fairly recent.
Share Improve this question edited Jun 2, 2021 at 17:03 wegry asked Jun 2, 2021 at 16:41 wegrywegry 8,1876 gold badges46 silver badges61 bronze badges 1-
2
Use a big int for both operands -
10n % 3n
? – jonrsharpe Commented Jun 2, 2021 at 16:43
1 Answer
Reset to default 8Both operands of an arithmetic operation involving a BigInt must be BigInts. In your case:
// BigInt literal
10n % 3n;
// BigInt explicit conversion
10n % BigInt(3);