Home | Mailing List | Blog | Tutorial Videos

Object Cloning (Object.assign) Comparison

Consider objects a and b below. What gets logged?

const a = { 
  stringField: 'Joe',
  nestedField: {field: 'Nested'},
  functionField: () => 'aReturn'
};
const b = Object.assign({},a);
b.stringField = 'Bob'
b.nestedField.field = 'Changed'
b.functionField = () => 'bReturn'
console.log(
  a.stringField,
  a.nestedField.field,
  a.functionField()
);

Select one: