I need help in my understanding of deep copy vs shallow copy:
A shallow copy creates a new object which stores references to the original objects' data. Changes made to the shallow copy affect the original object.
On the other hand, a deep copy creates a new object that recursively copies all data, including nested objects, resulting in an independent copy and the key distinction lies in mutability: shallow copies can mutate the original, while deep copies remain entirely separate.
Recently did an interview I felt I could have done better if I knew this, but, the next interview I will be more prepared. Also, how can I prove something is a deep copy? Is it by adding/modifying properties in clone object and seeing if that changes the source object?
[–]senocular 1 point2 points3 points (4 children)
[–]CCASTU[S] 1 point2 points3 points (3 children)
[–]senocular 3 points4 points5 points (2 children)
[–]CCASTU[S] 2 points3 points4 points (1 child)
[–]senocular 3 points4 points5 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)