DEV Community

Deeksha Sharma
Deeksha Sharma

Posted on

Careful use of Object.assign in JavaScript

Object.assign() creates a copy of an object to a target object and returns this target object.

Now, if empty object is not provided as the first parameter, it may end up mutating the original object.

The example below demonstrates how mutation happens:

Alt Text

Alt Text

Top comments (0)