Reference

Objects are never copied. They are passed around by reference.

  1. // Imagine I had a pizza
  2. var myPizza = {slices: 5};
  3. // And I shared it with You
  4. var yourPizza = myPizza;
  5. // I eat another slice
  6. myPizza.slices = myPizza.slices - 1;
  7. var numberOfSlicesLeft = yourPizza.slices;
  8. // Now We have 4 slices because myPizza and yourPizza
  9. // reference to the same pizza object.
  10. var a = {}, b = {}, c = {};
  11. // a, b, and c each refer to a
  12. // different empty object
  13. a = b = c = {};
  14. // a, b, and c all refer to
  15. // the same empty object