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

116
Visualizações
Referencing Object within Object Javascript Confusion

I am trying to create a reference to an object within an object, rather than creating a copy of it. I'm confused about reference vs. copy. What confuses me:

let master = {}
master['SomeObject'] = {a:"Something",b:"something"}
let subMaster = master['SomeObject']
subMaster['Test'] = true
console.log(master['SomeObject']['Test'])
//this WORKS as expected updating the original object
delete master['SomeObject']
console.log(subMaster)
//still shows content, and can continue to be manipulated? Shouldnt it show undefined?

Why does the reference still work even after deleting the original object? If I'm misunderstanding references, how can I make sure the original object is deleted so all references no longer work? I'm probably missing something fundamental and I appreciate anyones help!

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

0

delete does not physically delete the object from memory. It only removes that property from master. Since you are still referencing the object from your variable, and your variable has not fallen out of scope, the object still resides in memory.

Per MDN:

The JavaScript delete operator removes a property from an object

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