References

Beyond literals, any Object in JavaScript (including functions, arrays, regexp etc) are references. This means the following

Mutations are across all references

  1. var foo = {};
  2. var bar = foo; // bar is a reference to the same object
  3. foo.baz = 123;
  4. console.log(bar.baz); // 123

Equality is for references

  1. var foo = {};
  2. var bar = foo; // bar is a reference
  3. var baz = {}; // baz is a *new object* distinct from `foo`
  4. console.log(foo === bar); // true
  5. console.log(foo === baz); // false