I'm confused on what is the difference between modifying a variable itself and modifying a property of a variable when passing by reference.
Why didn't snippet below changed dog
object to null?
Don't they point to the same place in memory(aka passing by reference)?
let dog = {legs: 4}
let human;
human = dog;
human = null;
console.log(dog, human) // { legs: 4 } null
Below, on the opposite, changing a property legs
within the variable changes both variables:
let dog = {legs: 4}
let human;
human = dog;
human.legs = 2;
console.log(dog, human) // { legs: 2 } { legs: 2 }
Can somebody kindly explain or point me to the right direction to read more about this issue.