Skip to content
Onsite

Predict the output of a snippet mixing console.log, setTimeout 0, setImmediate, Promise.then and process.nextTick.

MediumP1Output

Predict the output of this Node.js script.

1console.log('start');
2setTimeout(() => {
3 console.log('timeout');
4 setImmediate(() => console.log('immediate'));
5 Promise.resolve().then(() => console.log('promise'));
6 process.nextTick(() => console.log('nextTick'));
7 console.log('end of timeout');
8}, 0);
9console.log('end');
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