6.1 Shallow copying vs. deep copying
There are two “depths” with which data can be copied:
- Shallow copying only copies the top-level entries of objects and Arrays. The entry values are still the same in original and copy.
- Deep copying also copies the entries of the values of the entries, etc. That is, it traverses the complete tree whose root is the value to be copied and makes copies of all nodes.
The next sections cover both kinds of copying. Unfortunately, JavaScript only has built-in support for shallow copying. If we need deep copying, we need to implement it ourselves.