Bigint and symbol
Concept and syntax
Use bigint for integer arithmetic beyond the safe integer range of number, and symbol for distinct identity values. A bigint literal has an n suffix; arithmetic cannot mix bigint and number without explicit conversion. Symbol("ticket") creates a new identity even when another symbol has the same description. This example targets ES2022, which supports bigint literals and Symbol declarations; the runtime must also implement them.
Working example
Compile standalone examples in a fresh directory with tsc --strict --target ES2022 --module commonjs --noEmitOnError main.ts, then node main.js.
const count: bigint = 9007199254740993n;const first: symbol = Symbol("ticket");const second: symbol = Symbol("ticket");console.log(String(count + 2n), first === second);Expected output (one line per log):
9007199254740995 falseCommon mistake
Intentionally invalid; check this snippet separately. Do not run it.
Expected compiler diagnostic: TS2365. Bigint arithmetic requires compatible operands. Use 2n if the intended value is an exact bigint integer.
Practice and recap
Add 10n to the large count. Create two new symbols with identical descriptions and compare them.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Bigint and symbol — knowledge check
Check the concept, apply it to a new choice, and interpret a compiler diagnostic.
Which literal is bigint?
What do two separate Symbol("ticket") calls create?
Which operand change preserves bigint arithmetic?
const result = 1n + 2;