Standard built-ins
Symbol.for()
Converts the key to a string and retrieves the corresponding global registry symbol, creating it if necessary. Calls with the same registry key return the same symbol. This is not a privacy mechanism or a guarantee that arbitrary fresh symbols are registered.
Formal Syntax & Structure
javascript syntaxjavascript
Symbol.for(key)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | any | Registry key converted to a string. |
Return Value
symbol
Registered symbol for the string key.
Working Example
Example Snippetjavascript
console.log(Symbol.for("record") === Symbol.for("record"));