Creating BigInt Values
What you'll learn: How to create BigInt values using the n suffix and the BigInt() constructor.
The Two Ways to Create a BigInt
Now that you know why BigInt exists (to handle integers larger than Number.MAX_SAFE_INTEGER), let's learn how to actually create them. JavaScript gives you two straightforward methods.
Method 1: The n Suffix (BigInt Literals)
The simplest way is to add an n to the end of any integer:
const big = 123456789012345678901234567890n;
const small = 42n;
typeof big; // "bigint"
Just append n to your number, and JavaScript treats it as a BigInt instead of a regular Number. No decimal points allowed — BigInts are integers only.
Method 2: The BigInt() Constructor
You can also convert Numbers or strings into BigInts using BigInt():
const fromNumber = BigInt(9007199254740991); // Safe integer converted
const fromString = BigInt("123456789012345678901234567890");
// This works too
const negative = BigInt(-42); // -42n
Important: Don't use new with BigInt() — it's not like Number(). Just call BigInt() directly.
Why Two Methods?
Use the n suffix when you're writing the number directly in your code. Use BigInt() when converting existing values (especially strings representing huge numbers that can't be typed as regular Numbers).
Key Takeaway: Create BigInts by adding n to integer literals (42n) or by calling BigInt() on numbers and strings — never mix BigInt with regular Number in arithmetic without explicit conversion.