Skip to content

Instantly share code, notes, and snippets.

@teffcode
Last active February 5, 2021 17:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teffcode/0509350d314b9d84639268ae4217f37b to your computer and use it in GitHub Desktop.
Save teffcode/0509350d314b9d84639268ae4217f37b to your computer and use it in GitHub Desktop.

👋🏼 Welcome 👋🏼

Quiz banner

Instagram | Twitter | LinkedIn


👅 Choose your language



🚀 English version


What is the output of the following code ?

  A. undefined
  B. Joker
  C. Parasite

👀 Click here to see the correct answer and explanation
Correct Answer Explanation
C. Parasite The this keyword in JavaScript refers to the object which is executing the current code. In this case, a function recommendedMovie() is being called from the global scope (the global scope means in the context of window object. We can optionally call it like window.recommendedMovie()). So, this.movie will return Parasite since it is the variable that is in the global scope.

If you want to know more about this keyword 👉🏼 this | MDN, Understanding the “this” Keyword in JavaScript | Medium, A guide to this in javascript | freecodecamp, This in JavaScript | geeksforgeeks, JavaScript — all about “this” keyword | Medium, this in JavaScript | TutorialsTeacher



🚀 Spanish version


¿ Qué imprime el siguiente código ?

  A. undefined
  B. Joker
  C. Parasite

👀 Haz click aquí para ver la respuesta correcta y su explicación
Respuesta correcta Explicación
C. Parasite La palabra clave this en JavaScript se refiere al objeto que está ejecutando el código actual. En este caso, se llama a la función recommendedMovie() desde el alcance global (el alcance global quiere decir en el contexto del objeto window. También, se puede llamar la función así: window.recommendedMovie()). Por lo tanto, this.movie devolverá Parasite, ya que es la variable que está en el alcance global.

Te dejo estos artículos por si quieres saber más sobre la palabra clave this 👉🏼 this | MDN, Understanding the “this” Keyword in JavaScript | Medium, A guide to this in javascript | freecodecamp, This in JavaScript | geeksforgeeks, JavaScript — all about “this” keyword | Medium, this in JavaScript | TutorialsTeacher



@leogomez23
Copy link

Ohh, ahora entiendo mejor this, gracias teff :3 son muy divertidos estos Quiz

@chescobarf
Copy link

Que extraño que ejecutando el mismo código sea distinta la respuesta a la que estas entregando...

@leogomez23
Copy link

Que extraño que ejecutando el mismo código sea distinta la respuesta a la que estas entregando...

image
A mi si se me ejecuta igual, algo debes estar colocando mal

@JoelNieto90
Copy link

Cuando ejecuto el código dentro de VS Code con CodeRun me devuelve "undefined", pero si lo ejecuto en la consola del navegador me retorna "Parasite".

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment