Deep and shallow copies are only for reference data types such as Object and Array. Shallow copy copies only Pointers to an object, not the object itself, and the old and new objects still share the same memory. But deep copy will create another identical object, the new object and the original object do not share memory, modify the new object will not change to the original object. The object.assign () method copies the enumerable properties of any number of source objects to the target Object and returns the target Object. But object.assign () makes a shallow copy, copying references to the Object’s attributes rather than the Object itself. Shallow copy

var obj = { a: {
              a: "wx".b: 18}};var obj2 = Object.assign({}, obj);
obj2.a.a = "li";
console.log(obj.a.a); // li
Copy the code

Deep copy

let obj = {
   name: 'wx'
};
let obj2 = Object.assign({},obj);
obj2.name = 'ww';
console.log(obj);//{name: "wx"}
Copy the code

When an object has only one layer, it is a deep copy