Instagram | Twitter | LinkedIn
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
¿ 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
Pueden consultar el siguiente material: https://es.javascript.info/array