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

159
Visualizações
Is the parent object reference changed if a child object is changed?

Suppose I have this

let a = { data: 'old' }

Lets say hypothetically that a has a reference to '123'

If I do

a.data = 'new'

Is the reference of a still pointing to '123' or has it been reallocated?

Thank you

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

0

You can make a very simple test for this:

let a = { data: "something" };
let b = a;

Now a and b are references to the exact same object.

a.data = "something else";
console.log(a === b); // true

Assigning to the property does not affect the value of a. Also:

console.log(b.data); // "something else"
about 4 years ago · Juan Pablo Isaza Relatório

0

Hypothetically, if a points to '123', you can assume that a.data points to '456'.

a->123

a.data -> 456

Now when you change a.data to "new" (say now at 789), you change the pointer for a.data so a would continue to point to the old value.

a->123

a.data->789

ReactJS specific: This is the reason why when dealing with object states, react may not re-render if you change a deep object key because the parent reference does not change.

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