const CopyEmployee = (emp) => {
emp.age = 45; //emp1 changes here..below doesnt impact emp1
//emp2 will be assigned below
emp = {
name: "Rahul",
age: 20,
};
return emp;
};
let emp1 = {
name: "Alok",
age: 50,
};
let emp2 = CopyEmployee(emp1);
console.log(emp1); //{name: 'Alok', age: 45}
console.log(emp2); //{name: 'Rahul', age: 20}
//emp2//
// emp = {
// name: "Rahul",
// age: 20,
// };
//emp1//
//only age gets changed... the reassign part doesnt impact emp1