Skip to content
Onsite

Output: spread-copy an object, then change a nested property on the copy

EasyP1Output

What does this code print?

1const original = { name: 'x', tags: { count: 1 } };
2const copy = { ...original };
3copy.name = 'y';
4copy.tags.count = 2;
5console.log(original.name);
6console.log(original.tags.count);
7console.log(original.tags === copy.tags);
Saved automatically

One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).

Hints

Saved automatically