Basically, spread operator deep copies the data if it is not nested.

For nested data, it deeply copies the topmost data and shallow copies of the nested data.

For example:

const oldObj = {a: {b: 2}, c: 5};

const newObj = {...oldObj};

newObj.a.b = 10; // change in nested

newObj.c = 20; // not nested

oldObj; //{a: {b: 10}, c: 5}; // b also changed

newObj; //{a: {b: 10}, c: 20};

oldObj.a === newObj.a;

//true - Shallow copy( same reference)

Hope this clarifies your concern Alfredo!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store