Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda