¿Qué imprime este código JavaScript?
let greeting;
greetign = {}; // Typo!
console.log(greetign);
- A:
{}
- B:
ReferenceError: greetign is not defined
- C:
undefined
Respuesta en el primer comentario.
For further actions, you may consider blocking this person and/or reporting abuse
Thomas Sentre -
amdiamond107 -
Ives van Hoorne -
Vishnu Sivan -
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)
La respuesta es:
A:
{}
En la primera línea declaramos
let greeting;
, al declarar una variable conlet
sin inicializarla, esta toma el valor deundefined
.En la segunda línea, se comete un error de tipeo
greetign = {};
, pero como la variable no esta declarada ni convar
,let
oconst
; Javascript tras bambalinas hace algo como lo siguiente aunque el programador no lo vea:Entonces
greetign
se crea como variable global, en el navegador en el objetowindow
y en un entorno de Node.js en el objetoglobal
.El código final se veria así: