JavaScript Symbol Methods

About This Index
This page is the JavaScript Symbol Methods index. The Symbol object has two static methods, and every symbol has three instance methods. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what a Symbol is on /js/symbol. Use this page when you need a specific method such as Symbol.for().
Symbol.for() and Symbol.keyFor() are called on the Symbol object itself. toString(), valueOf() and [Symbol.toPrimitive]() are called on a symbol you already have.
How to Call a Symbol Method
Call the static methods on Symbol, and the instance methods on a symbol:
const shared = Symbol.for("app.id"); // static: get a shared symbol
console.log(Symbol.keyFor(shared)); // static: "app.id"
const id = Symbol("id");
console.log(id.toString()); // instance: "Symbol(id)"
console.log(id.valueOf() === id); // instance: true
console.log(id[Symbol.toPrimitive]("default") === id); // instance: true JavaScript Symbol Methods Table
All method guides in this JavaScript tutorial series (5 tutorials), grouped by what they do.
Convert and read a symbol
3 methodsTurn a symbol into text, unwrap it from an object, and learn which conversions are allowed.
| Method | Description | Tutorial |
|---|---|---|
toString() | Return the symbol as text such as "Symbol(id)". Needed because + and template literals throw. | Open |
valueOf() | Return the primitive symbol, also from a wrapper object made with Object(symbol). | Open |
[Symbol.toPrimitive]() | Return the symbol itself for any hint. Number(symbol) and symbol + 1 still throw a TypeError. | Open |
Frequently Asked Questions
Start with Symbol.for()
Open the guide for shared symbols: syntax, examples, and FAQs.
9 people found this page helpful
