Home | Mailing List | Blog | Tutorial Videos

Object Cloning (JSON.parse + JSON.stringify) Comparison

Consider objects a and b below. What gets logged?

const a = { 
  stringField: 'Joe',
  numberField: 123,
  dateField: new Date('1995-12-17T03:24:00'),
  nestedField: {field: 'Nested'}
};
const b = JSON.parse(JSON.stringify(a));
console.log(
  a.stringField === b.stringField,
  a.numberField === b.numberField,
  a.dateField === b.dateField,
  a.nestedField.field === b.nestedField.field
);

Select one: