what is object clone code example
Example 1: clone javascript object
let clone = Object.assign({}, objToClone);
Example 2: javascript clone object
// syntax: let <newObjectName> = {...<initialObjectName>};
// example:
const me = {
name: 'Jakes',
age: 30,
};
const friend = {...me};
friend.age = 27;
console.log(friend.age); // 27
console.log(me.age); // 30
// -----------------------------
// BAD
// -----------------------------
const me = {
name: 'Jonas',
age: 30,
};
const friend = me;
friend.age = 27;
console.log(friend.age); // 27
console.log(me.age); // 30