Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created May 13, 2020 12:21
Show Gist options
  • Save teffcode/bf0a0f270071269d4669f2f9af12f687 to your computer and use it in GitHub Desktop.
Save teffcode/bf0a0f270071269d4669f2f9af12f687 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. {item: "🥦"}
  B. {item: "🍊"}
  C. undefined

👀 Click here to see the correct answer and explanation
Correct Answer Explanation
A. {item: "🥦"} The output will {item: "🥦"} because we're dealing with objects here. Objects are passed by reference, that is, fruits and vegetables 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. {item: "🥦"}
  B. {item: "🍊"}
  C. undefined

👀 Haz click aquí para ver la respuesta correcta y su explicación
Respuesta correcta Explicación
A. {item: "🥦"} La respuesta es {item: "🥦"} porque estamos tratando con objetos y los objetos se pasan por referencia, es decir, fruits y vegetables 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

var fruits = { // Creamos el objeto fruits
items: "🍊"
};
var vegetables = fruits; // Copiamos la referencia del objeto fruits.

vegetables.item = "🥦"; // reasignamos a item por la referencia vegetable

console.log(fruits); // {item: "🥦"}

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