Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created May 15, 2020 13:52
Show Gist options
  • Save teffcode/3bb2b9bcd55b7a0d623e9fe59ec53737 to your computer and use it in GitHub Desktop.
Save teffcode/3bb2b9bcd55b7a0d623e9fe59ec53737 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. ["🌮", "🥗", "🍗"]
  B. ReferenceError
  C. ["👕", "🥗", "🍗"]

👀 Click here to see the correct answer and explanation
Correct Answer Explanation
C. ["👕", "🥗", "🍗"] Arrays are object in JavaScript and they are passed and assigned by reference. Changing the first element of the clothes, will also modify food: That is, food and clothes point to the same object in memory 🧠

If you want to know more about "by reference vs. by value" 👉🏼 Explaining Value vs. Reference in Javascript | Medium and All you need to know on by reference vs by value | freeCodeCamp



🚀 Spanish version


¿ Qué imprime el siguiente código ?

  A. ["🌮", "🥗", "🍗"]
  B. ReferenceError
  C. ["👕", "🥗", "🍗"]

👀 Haz click aquí para ver la respuesta correcta y su explicación
Respuesta correcta Explicación
C. ["👕", "🥗", "🍗"] Los arrays son objetos en JavaScript y se pasan y asignan por referencia. Si cambiamos el primer elemento de clothes también se modificará el array de food, ya que, food y clothes apuntan al mismo objeto en la memoria 🧠

Te dejo estos artículos por si quieres saber más sobre el paso por valor y paso por referencia 👉🏼 Explaining Value vs. Reference in Javascript | Medium and All you need to know on by reference vs by value | freeCodeCamp



@JoelNieto90
Copy link

Pueden consultar el siguiente material: https://es.javascript.info/array

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