r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

3

u/tomius May 28 '19

You're right. It should be

const obj2 = Object.assign({}, obj1)

1

u/johnslegers May 29 '19

Even Object.assign can be tricky when you have nested objects!

See https://repl.it/repls/FloralwhiteGruesomeSystemcall

1

u/tomius May 29 '19

Yeah, yeah. I use deep copy in those cases. Or do it manually if it's not too much. Specially tricky when using redux.

1

u/johnslegers May 29 '19

Aren't you supposed to use immutable data types in Redux to avoid this trickiness?