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
largeNumberas the bigint9007199254740993n - Create
anotherLargeas the bigint1000000000000000000n - Create
sumby adding those two bigints - Create
userIdwithSymbol('user-id') - Create
anotherIdwith the same descriptionSymbol('user-id') - Create
areEqualby comparinguserId === anotherId, then inspect the result - Export all six names
Required exports
largeNumber, anotherLarge, sum, userId, anotherId, areEqualCompletion criteria
largeNumberis9007199254740993n(typeof"bigint")anotherLargeis1000000000000000000nsumequals the sum of those two bigintsuserIdandanotherIdare both symbolsareEqualreflects whether those two symbols compare equal with===
π° BigInt literals use the
n suffix.π MDN - BigInt
π MDN - Symbol


