Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Is there a reason to prefer Symbol.keyFor() over Symbol.prototype.description?

In JavaScript, I can create Symbol -primitives like this:

const ex1 = Symbol('example1');
const ex2 = Symbol.for('example2');

And I can get the original string that was used to create the Symbol by accessing the Symbol.prototype.description, or by calling the Symbol.keyFor() -method like so:

ex1.description; // 'example1'
ex2.description; // 'example2'
// OR
Symbol.keyFor(ex1); // undefined
Symbol.keyFor(ex2); // 'example2'

My questions are;

  • Is there any difference between the two methods, other than Symbol.keyFor not working for Symbols that are not in the global registry (i.e. created from Symbol.for())? It seems to me they are otherwise used to achieve the exact same thing.
  • Is there a reason to ever prefer using Symbol.keyFor() instead of Symbol.prototype.description? Since the description works for all Symbols, while keyFor works only for ones in the global registry.
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda