Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active February 17, 2021 16:46
Show Gist options
  • Save mr-pascal/7460e2b7a655cd531ea530b668666f7e to your computer and use it in GitHub Desktop.
Save mr-pascal/7460e2b7a655cd531ea530b668666f7e to your computer and use it in GitHub Desktop.
// Objects
(() => {
let a = { content: 'a' };
let b = a;
a.content = 'something else';
console.log(`-- Object --`);
console.log(`a: ${JSON.stringify(a)}`); // a: {"content":"something else"}
console.log(`b: ${JSON.stringify(b)}`); // b: {"content":"something else"}
console.log(`\n`);
})();
// Nested Objects
(()=>{
let a = { arr: [] };
let b = Object.assign({}, a);
a.arr.push('a');
console.log(`-- Nested Object --`);
console.log(`a: ${JSON.stringify(a)}`); // a: "arr":["a"]}
console.log(`b: ${JSON.stringify(b)}`); // b: "arr":["a"]}
console.log(`\n`);
})();
// Arrays
(() => {
let a = ['a'];
let b = a;
a.push('b');
console.log(`-- Array --`);
console.log(`a: ${JSON.stringify(a)}`); // a: ["a","b"]
console.log(`b: ${JSON.stringify(b)}`); // b: ["a","b"]
console.log(`\n`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment