2

Given a BigInt in JS, how do you compute 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.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt which is fairly recent.

wegry
  • 7,046
  • 6
  • 39
  • 59

1 Answers1

5

Both operands of an arithmetic operation involving a BigInt must be BigInts. In your case:

// BigInt literal
10n % 3n;

// BigInt explicit conversion
10n % BigInt(3);
Altareos
  • 843
  • 6
  • 13