-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
56 lines (36 loc) · 1.18 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: Symbol.keyFor()
slug: Web/JavaScript/Reference/Global_Objects/Symbol/keyFor
page-type: javascript-static-method
browser-compat: javascript.builtins.Symbol.keyFor
---
{{JSRef}}
The **`Symbol.keyFor()`** static method retrieves a shared symbol
key from the global symbol registry for the given symbol.
{{EmbedInteractiveExample("pages/js/symbol-keyfor.html")}}
## Syntax
```js-nolint
Symbol.keyFor(sym)
```
### Parameters
- `sym`
- : Symbol, required. The symbol to find a key for.
### Return value
A string representing the key for the given symbol if one is found on the [global registry](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry); otherwise, {{jsxref("undefined")}}.
## Examples
### Using keyFor()
```js
const globalSym = Symbol.for("foo"); // create a new global symbol
Symbol.keyFor(globalSym); // "foo"
const localSym = Symbol();
Symbol.keyFor(localSym); // undefined
// well-known symbols are not symbols registered
// in the global symbol registry
Symbol.keyFor(Symbol.iterator); // undefined
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("Symbol.for()")}}