News from the Field
A channel with tips on modern AI development. Join!
⊗jsSpSyGN 58 of 294 menu
◀ ▶

Retrieving a symbol name in JavaScript

Having a variable with a symbol, you can retrieve its name in the global registry. This is done using the Symbol.keyFor method. Let's try. Let's create a symbol with a name:

let sym = Symbol.for('test');

Get its name by its variable:

let key = Symbol.keyFor(sym); console.log(key); // shows 'test'

Given two symbols:

let sym1 = Symbol.for('test1'); let sym2 = Symbol.for('test2');

Retrieve their names.

← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline