Difference between copying an object through assignment operator and _.clone() function ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report There are two ways, we can copy the object in javascript, first is by using the assignment operator i.e. '=' and the second is by using the 'clone' function. In this article, we'll discuss what is the difference between both of them. By using the _.clone() function: Both of these methods copy objects but they are very different from each other. This method creates a new object and copies the value of an old object into it, so if there is any change in the old object then it does not affect the content of the new object. The _.clone() method is used to create a shallow copy of the value. Example: JavaScript <script> const _ = require("lodash"); var original = { Name: "Aman", color: "Black" }; var duplicate = _.clone(original); console.log(duplicate); original.Name = "Vivek"; console.log(duplicate); </script> Output: { Name: 'Aman', color: 'Black' } { Name: 'Aman', color: 'Black' } As we can see in this example, if we use clone-function then the duplicate object doesn't get affected by it. By using the assignment operator: This method is different from the clone function as we use the '=' operator in this for coping the object and if we try to change the original object then the duplicate objects also get changed with it. We can see this in the example below. Example: JavaScript <script> var original = { Name: "Aman", color: "Black" }; var duplicate = original; console.log(duplicate); original.Name = "Vivek"; console.log(duplicate); </script> Output: { Name: 'Aman', color: 'Black' } { Name: 'Vivek', color: 'Black' } As we can see in this example, when we try to change the content of the original object then that change also gets reflected in the duplicate object. Comment More infoAdvertise with us Next Article Difference between copying an object through assignment operator and _.clone() function ? V vivekdembla1 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2022 JavaScript-Lodash +1 More Similar Reads Difference between Lodash _.clone() method and '=' operator to copy Objects In this article, we will learn about the difference between using the _.clone() method in Lodash and using the '=' operator to copy objects. Both of these methods are used to create a copy of an object in JavaScript. However, both work in very different ways. Using _.clone() Method: The _.clone() me 3 min read Difference Between Object.assign and Spread Operator in JavaScript The Object.assign() and the Spread Operator (...) are commonly used for copying properties from one object to another. While they can achieve similar outcomes, they have distinct characteristics and use cases. This article will explain the differences between the Object.assign() and the spread opera 3 min read Difference between React.cloneElement and this.props.children React.cloneElement and this.props.children are functionalities within React that play distinct roles in manipulating React components and elements. Although both are employed for this purpose, they are utilized in different contexts. Let's delve into the specifics of each. Table of Content React.clo 3 min read Difference Between Shallow copy VS Deep copy in Pandas Dataframes The pandas library has mainly two data structures DataFrames and Series. These data structures are internally represented with index arrays, which label the data, and data arrays, which contain the actual data. Now, when we try to copy these data structures (DataFrames and Series) we essentially cop 4 min read How to create clone of any object using jQuery ? In this article, we will learn to create a clone of an object using jQuery. This can be achieved using the extend() method of jQuery. The extend() method is used to merge the contents of multiple objects into the object passed as the first parameter. This can be used to clone an array as we can pass 3 min read Like