DEV Community

Deeksha Sharma
Deeksha Sharma

Posted on

6

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more