Explica este código JavaScript
const persona = {
id: 1,
nombre:"Fernando",
};
persona.nombre = "Pedro";
console.log(persona.nombre);
- A.
Pedro
- B.
Fernando
- C.
null
- D.
TypeError
Respuesta en el primer comentario.
For further actions, you may consider blocking this person and/or reporting abuse
Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.
One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.
...
Pelle Wessman -
Pramod Dutta -
Sachin Sharma -
Phani Murari -
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 (2)
Respuesta
A.
Pedro
Inicialmente el objeto
persona
tiene en la llavenombre
la cadenaFernando
pero luego hacemospersona.nombre = "Pedro"
que actualiza el valor denombre
perdiendo la cadenaFernando
.A. Pedro
Aún siendo una constante (const), finalmente es un objeto, cuyos valores sí pueden ser cambiados. De allí que la línea 5 cambie el nombre de Fernando a Pedro.