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

205
Visualizações
How Javascript stores objects as keys

We know that

let obj1 = {};
obj1.x = "value";

let obj2 = {"key":"value"};
obj2[obj1] = "another value";
console.log(obj2[obj1]);

Above will print the "another value" properly on the console. Need to understand how. Does it store the address of obj1 for the key to match with the value?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Object property names can be strings or Symbols. Anything that is not a Symbol will be converted to a string.

A plain object's toString method will convert it to "[object Object]".

You can see that string if you log the entire object.

let obj1 = {};
obj1.x = "value";

let obj2 = {"key":"value"};
obj2[obj1] = "another value";
console.log(obj2);

console.log(obj1.toString());

This does, of course, mean that if you try to set ob2[obj3] at some point, with another object, then even if obj3 is a different object it will still be converted to the same string and overwrite the previous value.

about 4 years ago · Juan Pablo Isaza Relatório
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