JavaScript Interview Question #182

What is BigInt in JavaScript?

Advanced JavaScript, Practical Problems & Senior Interview Scenarios Senior Advanced

Quick Interview Answer

BigInt is a primitive numeric type for integers that may exceed the safe integer range of the Number type. A BigInt literal is commonly written with an n suffix.

Detailed Explanation

BigInt is a primitive numeric type for integers that may exceed the safe integer range of the Number type. A BigInt literal is commonly written with an n suffix.

Number and BigInt are different numeric types and generally cannot be mixed directly in arithmetic operations. BigInt represents integers only and is not a replacement for decimal or floating-point calculations.

Code Example

const large =
    9007199254740993123456789n;

const another = BigInt(
    "9007199254740993123456790"
);

console.log(large + 1n);
console.log(another > large); // true