Code Lab

Timer: 5 min, like in an interview. Hints and autocomplete are off while it runs

Shallow copy

EasyObjects5 min

What does this code print? Write one line for each console log call.

const user = { name: 'Anna', address: { city: 'Riga' } };
const copy = { ...user };

copy.name = 'Olga';
copy.address.city = 'Tallinn';
console.log(user.name);
console.log(user.address.city);
console.log(copy.address === user.address);

const deep = structuredClone(user);
deep.address.city = 'Vilnius';
console.log(user.address.city);

Source

Your answer
Loading the editor...
Press Run to see the test results here