Skip to content

Instantly share code, notes, and snippets.

@chidumennamdi
Created August 22, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chidumennamdi/2c78f6173791511a96fa2789af1ea9c9 to your computer and use it in GitHub Desktop.
Save chidumennamdi/2c78f6173791511a96fa2789af1ea9c9 to your computer and use it in GitHub Desktop.
let obj= { name: "Chidume" , id:2}
// creates variable obj on the stack and stores { name: "Chidume" } on the heap.
//obj has the memory address where { name: "Chidume" } is stored on the heap
// obj == #001 (let's take #001 is the number of the memory cell)
obj.name = "David"
// This refers to the memory #001 and changes the `name` property.
var o = obj // creates variable `o` on the stack and points it to #001.
console.log(o === obj) // true
// `===` checks if the memory address pointed to by `o` is equal to the memory address pointed to by `obj`.
obj = { name: "David" }
// This creates `{ name: "David" }` on the heap and points obj to the memory address number #001
// obj changes from #001 to #002
console.log(o === obj) // false
// It will print `false` because, now `obj` points to #002 and o points to #001
console.log(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment