Js Bigint in JavaScript
? JavaScript BigInt
What is BigInt?
A built-in JavaScript type to represent integers larger than the safe limit for
Number.Normal
Numbercan safely represent integers up to ±(2^53 - 1).BigIntcan handle arbitrarily large integers.
How to Create a BigInt?
Append
nto the end of an integer literal:
const big = 123456789012345678901234567890n;Use the
BigInt()constructor:
const big2 = BigInt("123456789012345678901234567890");Operations with BigInt
Supports usual arithmetic operators:
+,-,*,/,%,**.Can’t mix
BigIntwithNumberdirectly — you must explicitly convert.
const a = 10n;const b = 20n;console.log(a + b); // 30n// Mixing types causes errorconst c = 10;// console.log(a + c); // TypeError// Convert number to BigIntconsole.log(a + BigInt(c)); // 20nComparison with Numbers
console.log(10n > 5); // trueconsole.log(10n == 10); // true (value comparison)console.log(10n === 10); // false (different types)Use Cases for BigInt
Cryptography
High precision math
Working with large datasets or IDs
Limitations
No support for decimals (BigInt is integer-only).
Some built-in Math functions don’t work with BigInt.
Use carefully when interoperating with APIs expecting numbers.
If you want, I can show examples of BigInt in practical use cases or how to convert between Number and BigInt safely!