shallow & deep copies of objects using various methods
Syed Abdul Momin
Sr. Frontend Developer || Angular Expert || Typescript || JavaScript || Crafting Seamless User Experiences || Boost 100+ brands identity through my services
Shallow Copy:
A shallow copy of an object creates a new object, but it only copies the top-level structure of the original object. If the original object contains nested objects, those nested objects are not cloned but rather referenced in the shallow copy.
As you can see, modifying the nested object `b` in the shallow copy also affects the original object.
Deep Copy:
A deep copy of an object creates a new object and recursively copies all nested objects within it, so any changes made to the copied object do not affect the original object.
In this case, modifying the nested object b in the deep copy does not affect the original object.