DEV Community


Discussion on: Best way to copy an object in JavaScript?

gobeli profile image
Etienne • Edited

It does work, but not for nested objects. i.e.:

const x = {
  foo: {
    bar: false
const y = Object.assign({}, x);
console.log(x === y); // outputs false
console.log( ===; // outputs true
Forem Open with the Forem app