Skip to content
Onsite

Output: closure created, then the captured variable changed before the closure runs

EasyP2Output

What does this code print?

1let msg = 'first';
2const show = () => console.log(msg);
3msg = 'second';
4show();
5
6function make() {
7 let v = 1;
8 const get = () => v;
9 v = 2;
10 return get;
11}
12console.log(make()());
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