Before understanding deep copy and shallow copy, you need to understand some basic concepts. The variable types stored in memory are divided into value types and reference types.
1. Storage characteristics of value type assignment: copy all the data in the variable and store it to a new variable.
For example: var num = 123; var num1=num;
The number stored in the variable is 123. Then copy the data one copy, which means copying 123. Then there are 2 arrays in memory; assigning the copy data to num2, the characteristic is that there are two copies of data in memory. This can be understood as a shallow copy.
2. Assignment of reference type.
var o={name:'Zhang San'};
var obj=o;
Assignment is to copy a copy of the data stored in the variable o and then assign the data to obj. There is 1 point of data in memory, and the name attribute modified by obj will affect the name in o.
If all reference structures of the data are copied when copying, then the data is independently copied in memory;
If the attributes of the current object are copied only when copying, and the attributes are reference types are not considered, then it is a shallow copy;
Copy: Copy a copy. It refers to copying object data;
When discussing deep copy and shallow copy, it is necessary to ensure that the properties of the object are also reference types.
The above brief discussion on the deep and shallow object-oriented copy in JavaScript is all the content I share with you. I hope you can give you a reference and I hope you can support me more.