Shallow copy:

If it is a primitive copy, the new value does not affect the old value,

If it is a reference copy, only the first layer will be copied and the reference will point to the same address as the old value

There is another understanding of reference type copy:

A shallow copy is a bitwise copy of an object that creates a new object with an exact copy of the original object’s property values. If the property is of a primitive type, the value of the primitive type is copied. If the property is a memory address (reference type), the memory address is copied, so if one object changes the address, the other object will be affected. That is, the default copy constructor only copies objects shallowly (member by member), that is, only the object space is copied, not the resource. (reference)

Deep copy:

Regenerates an object with a new address, the same content as the original address, but not affecting each other

Shallow copy method:

1.
const target = { a: 1.b: 2 };
const source = { b: 4.c: 5 };

const returnedTarget = Object.assign(target, source);

2.

function shallowCopy(src) {
   var dst = {};
   for (var prop in src) {
       if(src.hasOwnProperty(prop)) { dst[prop] = src[prop]; }}return dst;
}
3.
[...arr2] = arr;
Copy the code

Deep copy method:

1.
function deepClone(obj){
    let objClone = Array.isArray(obj)? [] : {};if(obj && typeof obj==="object") {for(key in obj){
            if(obj.hasOwnProperty(key)){
                // Determine whether the oJB child is an object, if so, recursively copy
                if(obj[key]&&typeof obj[key] ==="object"){
                    objClone[key] = deepClone(obj[key]);
                }else{
                    // If not, simply copyobjClone[key] = obj[key]; }}}}return objClone;
} 
2.
JSON.parse(JSON.stringify(arr))
// Disadvantages: not function, time, NAN friendly, returns NULL
Copy the code