JavaScriptES6+ Features

2 items

Code QuizIntermediate

Spread makes a shallow copy

The spread operator only copies the top level, so nested objects stay shared between the copy and the original.

Codejavascript
const original = { name: 'Ada', address: { city: 'London' } };
const copy = { ...original };

copy.address.city = 'Paris';

console.log(original.address.city); // expected 'London'

The developer expected original.address.city to stay 'London', but it becomes 'Paris'. What is the bug?