Skip to content
Onsite

Output: assign an object to a second variable, mutate through it, then reassign it

EasyP1Output

What does this code print?

1const a = { n: 1 };
2let b = a;
3b.n = 2;
4console.log(a);
5b = { n: 3 };
6console.log(a);
7console.log(b);
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