Yogesh Chavan
1 min readApr 12, 2020

--

Mike Figueroa for non-primitive types like array, objects when we assign any value, it’s not the actual value that gets assigned but only reference of the allocated memory address is stored in that variable. So when we say, array = [], [] is just a short hand way of allocating some space in memory with no data in it and so array will contain only the reference of the allocated memory space.
Same is true with objects for ex. when we say obj = { name: ‘David’}, the obj variable does not contain the object itself but just reference of the allocate memory space and in that memory space the actual object is stored.

The behavior is same for objects also.

let obj = { name: ‘David’ };
let newObj = obj;

console.log(obj); // { name: ‘David’ }
console.log(newObj); // { name: ‘David’ }

obj = null;

console.log(obj); // null
console.log(newObj); // { name: ‘David’ }

I hope it clears your doubt.

--

--

Yogesh Chavan
Yogesh Chavan

No responses yet