17
Jun
As you might know, Javascript uses pass-by-reference when passing an object, array, or function to a new variable. When you pass an object, array, or function to a new variable, a reference (memory address) to the object is passed. Any modification to the object's properties in the new variable will be reflected in the original object since they both point to the same memory location. const original = { name: 'Alice' }; const newVariable = original; newVariable.name = 'Bob'; console.log(original); // { name: 'Bob' }; Enter fullscreen mode Exit fullscreen mode To solve this issue we can use Object.assign() or…