BigInt and Symbol
Bigint and Symbol
π¨βπΌ TypeScript has two more primitive types that are less commonly used but good
to know about:
bigint and symbol.BigInt - Large Integers
Regular
number has limitsβit can't accurately represent integers larger than
Number.MAX_SAFE_INTEGER (about 9 quadrillion). bigint handles arbitrarily
large integers:const big: bigint = 9007199254740993n // Note the 'n' suffix
const alsoBig: bigint = BigInt('9007199254740993')
// BigInt arithmetic
const sum = 1000000000000000000n + 1n // Works correctly!
BigInt and number don't mix directly. You can't do
5n + 3βyou need to
convert one type to the other.Symbol - Unique Identifiers
Symbols are guaranteed-unique values, useful as object keys when you need to
avoid name collisions:
const id: symbol = Symbol('userId')
const anotherId: symbol = Symbol('userId')
id === anotherId // false - each Symbol() creates a unique value!
Symbols are often used for "hidden" object properties or library-internal keys.
π¨ Open
and:
- Create a bigint literal with the
nsuffix - Perform arithmetic with bigint values
- Create symbols and observe their uniqueness
π° BigInt literals use the
n suffix.π MDN - BigInt
π MDN - Symbol


