symbol / bigint symbol and bigint
Last updated: 2026-10-22
symbol / bigint symbol and bigint
symbol creates globally unique, unrepeatable values — good for object keys and constant tokens. bigint holds arbitrary-precision integers beyond number's safe range.
| Group | Basic Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
const key = Symbol("id"); // unique; "id" is just a description
const big: bigint = 9007199254740993n; // exact beyond the safe range
⚙️ Parameters
| Symbol(desc) | The argument is a description (readable via .description) and does not affect uniqueness |
|---|---|
| 123n | bigint literals end with n; BigInt(123) converts too |
Returns:None — symbol/bigint are basic type annotations; Symbol() and BigInt() are runtime functions.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
false order
9007199254740994
(Runtime output after transpilation; two Symbols with the same description are not equal — that is what unique means)
💡 Notes
ℹ️ Info Symbol("a") !== Symbol("a") — descriptions are just labels; use Symbol.for("a") for a shared, registered symbol.
⚠️ Note bigint cannot mix with number directly (9007199254740993n + 1 errors) and JSON.stringify cannot serialize it.
💡 Tip Symbol keys are skipped by Object.keys and for...in — perfect for internal metadata.
🏷️ Related Basic Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q When do I need bigint?
A When integers exceed 2^53 - 1 or must stay exact: snowflake IDs, crypto math, large cent totals. Within range, plain number is fine.
Q What is symbol actually used for?
A Three typical uses: non-colliding internal object keys, module-level unique constants, and language protocols via well-known symbols like Symbol.iterator.
Q Are two Symbol("a") calls equal?
A No — every Symbol() call creates a fresh value. To share one across modules use Symbol.for("a"), which returns the same instance for the same key.