¿Qué imprime este código JavaScript?
let person = { name: "Lydia" };
const members = [person];
person = null;
console.log(members);
- A:
null
- B:
[null]
- C:
[{}]
- D:
[{ name: "Lydia" }]
Respuesta en el primer comentario.
For further actions, you may consider blocking this person and/or reporting abuse
The harsh reality for JS Developers: If you don't study the fundamentals, you'll be just another “Coder”. Top learnings on how to get to the mid/senior level faster as a JavaScript developer by Dragos Nedelcu.
Andrew Zachary -
Jessica Alves -
Reekdev Ray -
Nathanael -
Once suspended, duxtech will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, duxtech will be able to comment and publish posts again.
Once unpublished, all posts by duxtech will become hidden and only accessible to themselves.
If duxtech is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Cristian Fernando .
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag duxtech:
Unflagging duxtech will restore default visibility to their posts.
Top comments (1)
Respuesta:
[{ name: "Lydia" }]
Cuando hacemos:
En realidad estamos realizando una copia a la referencia de
person
, tantoperson
comomembers
apuntan a la misma referencia del objeto en memoria.Por este motivo al hacer:
Cambiamos el valor de
person
anull
peromembers
conserva la referencia al objeto y por ello también su valor.