DEV Community

Discussion on: JavaScript Interviews: Create a deep copy of an object

pris_stratton profile image
pris stratton

My first thought was wouldn’t I just use Object.assign, is that a valid answer?

ninofiliu profile image
Nino Filiu

Object.assign is equivalent to object spread and only copies the top level keys of an object

const a = { b: { c: 10 } }
const clonedA = { ...a }
a.b.c // 11
Enter fullscreen mode Exit fullscreen mode