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.

GroupBasic Types
KindType
Strict modeNot 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
123nbigint 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.
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏