-
-
Save chidumennamdi/2c78f6173791511a96fa2789af1ea9c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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