Table of Contents
- Code and its Explanation
- Other Related Concepts
In case you are curious about how the Object.assign method assigns properties, it involves getters and setters subsequently it gets the properties from the source using [[Get]] and stores them in the target using [[Set]].
The parameters used are explained below:
Target - The Target Object is where the copied source properties are stored and returned when the object.assign is used.
Source - The Source Objects are the objects from which the values and properties have to be copied. Unlike the Target, multiple source objects parameters can be passed.
Code and its explanation:
Limitations and caveats
- A TypeError is thrown in case the property is non-writable, however, in such case, the target object would still contain properties of the previously added values
- Object.assign() does not throw errors on null or undefined sources
- Ensure that the source object you are trying to clone is not a reference to an object, since it would only copy the reference values