Explica este código JavaScript
Dificultad: Básico
let a = 1;
{
let a = 2;
}
console.log(a);
A. 1
, 2
B. 2
C. 1
D. SyntaxError
Respuesta en el primer comentario.
For further actions, you may consider blocking this person and/or reporting abuse
Mr. G -
Eden Federman -
Bap -
Bogomil Shopov - Бого -
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:
C.
1
Las variables declaradas con
let
tienen scope de bloque, por ende la variablea
tiene su propio scope que es diferente al de la variableb
y por este motivo no existe conflicto con sus nombres.En otras palabras, la variable
a = 2
esta asilada en su bloque, mientras que la variablea = 1
esta en el mismo scope que elconsole.log(a)
, esto explica por que mostramos por consola1
.