Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Javascript has built-in support for performing the mod (%) operation on large numbers using the BigInt data type. BigInts are a built-in data type in Javascript that support integers of arbitrary length, so they can handle very large numbers without losing precision or causing an overflow error.

To use BigInts for the mod (%) operation, simply create a BigInt object for the numerator and denominator, then use the mod (%) operator as usual. Here's an example:

let a = BigInt('100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
let b = BigInt(123456789);
let result = a % b;
console.log(result) // prints 51112630n

Notice that the result of the mod operation is suffixed with the letter "n", which indicates that it's a BigInt object. You can convert it to a regular number using the Number() function if needed:

let regularNumber = Number(result);
console.log(regularNumber) // prints 51112630