Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created June 24, 2020 06:25
Show Gist options
  • Save teffcode/ab383734fb4976523bd719012e2a2781 to your computer and use it in GitHub Desktop.
Save teffcode/ab383734fb4976523bd719012e2a2781 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. Reference Error
  C. 🍰

👀 Click here to see the correct answer and explanation
Correct Answer Explanation
A The this value (internally) is not actually bound to the arrow function. Normal functions in JavaScript bind their own this value, however the this value used in arrow functions is actually fetched lexically from the scope it sits inside (where the object was defined). In this case, this refers to window object, so, window.cake = undefined.

Explanation based on 👉🏼 ES6 arrow functions, syntax and lexical scoping & Methods in ES6 objects: using arrow functions



Spanish version 🚀


¿ Qué imprime el siguiente código ?

  A. undefined
  B. Reference Error
  C. 🍰

👀 Haz click aquí para ver la respuesta correcta y su explicación
Respuesta correcta Explicación
A El valor de this no está realmente vinculado a la función flecha (o arrow function en inglés). Las funciones normales en JavaScript vinculan su propio valor this, sin embargo, el valor de this utilizado en las funciones flecha en realidad se obtiene léxicamente del ámbito en el que se encuentra (en donde se definió el objeto). En este caso, this se refiere al objeto window, por lo que, window.cake = undefined.

Explicación basada en 👉🏼 ES6 arrow functions, syntax and lexical scoping & Methods in ES6 objects: using arrow functions



@hugok2k
Copy link

hugok2k commented Jun 24, 2020

Hola Teff! gracias por los quiz 😊, sigo aprendiendo aun y esto ayuda muchísimo. Un pequeño detalle, vienes arrastrando un inconveniente con los links internos english y spanish version en los 3 últimos quiz, solo es un guion 🙌

@teffcode
Copy link
Author

Hola @hugok2k ! 😱 Muchas gracias !!! Creo que es porque cambié la posición del emoji y al link olvidé quitarle un guión medio que separaba el emoji del texto 😅 En cuanto tenga un tiempito lo corrijo ! Nuevamente, mil graciasss !

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