Shallow Copy Example

PHOTO EMBED

Sat Jun 26 2021 21:06:10 GMT+0000 (Coordinated Universal Time)

Saved by @ssunchu28 #javascript

const employee = {
    name: 'Siddharth',
    age: 35
};

const copyOfEmployee = employee;
console.log(employee, 'employee');
console.log('------------After Modification-----------');
copyOfEmployee.age = 29;
/*
Here you would expect employee object wouldn't change, but copyOfEmployee 
and employee object both share same memory address
*/
console.log(employee, 'employee');
content_copyCOPY