This is often not sufficient when dealing with large integers, such as those used in cryptography or financial applications.
n to the end of a number literal, like this:
const bigIntValue = 1234567890123456789012345678901234567890n;
You can also convert a number to a
BigInt using the
const numberValue = 1234567890123456789012345678901234567890; const bigIntValue = BigInt(numberValue);
Once you have a
BigInt value, you can perform all the basic arithmetic operations on it, such as addition, subtraction, multiplication, and division:
const x = 1234567890123456789012345678901234567890n; const y = 98765432109876543210987654321098765432109n; const sum = x + y; const difference = x - y; const product = x * y; const quotient = x / y;
n suffix or the
BigInt() function when creating or converting a
BigInt value, and you cannot perform arithmetic operations between a
BigInt and a regular number without converting one of them first.
BigInt values have a separate set of comparison operators, such as
==. Regular comparison operators do not work with