Js Does Object Assign Create Deep Copy Or Shallow Copy

    Table of contents

JS: Does Object.assign() create deep copy or shallow copy

Tags: javascript , object , deep-copy , shallow-copy Answers: 1 | Viewed 40,693 times



I just came across this concept of


var copy = Object.assign({}, originalObject);

which creates a copy of original object into the "copy" object. However, my question is, does this way of cloning object create a deep copy or a shallow copy?


PS: The confusion is, if it creates a deep copy, then it would be the easiest way to clone an object.


Some Answers For Js Does Object Assign Create Deep Copy Or Shallow Copy

Please leave your answer here: