Difficulty: ⭐ ⭐
A:
Both shallow copy and deep copy create a copy of data.
JS is divided into primitive types and reference types. There is no difference between shallow and deep copies of primitive types. The deep and shallow copies we discuss are only for reference types.
-
Both shallow and deep copies copy values and addresses to address the problem of reference type assignments affecting each other.
-
But shallow copies only replicate at one level, the underlying reference types are still shared memory addresses, and the original and copied objects still interact.
-
Deep copy is an infinite level copy. The original object after deep copy does not interact with the copied object.
Many articles on the network feel that reference type assignment is shallow copy, misleading a lot of people, I in this article revealed the difference between deep copy and shallow copy, you can refer to it.
Easy to get JS shallow copy, deep copy
At the end
If my article is helpful to you, your 👍 is my biggest support ^_^
I’m Allyn, export insight technology, goodbye!
The last:
What are the common methods of “Front-end Daily Ask (15)” JavaScript strings?