Home | Mailing List | Blog | Tutorial Videos

Object Cloning (JSON.parse + JSON.stringify)

Consider objects a and b below. What gets logged?

const a = { 
  stringField: 'Joe',
  nestedField: {field: 'Nested'}
};
const b = JSON.parse(JSON.stringify(a));
b.stringField = 'Bob'
b.nestedField.field = 'Changed'
console.log(
  a.stringField,
  a.nestedField.field
);

Select one: