BrowservsNode.js

Event Loop Deep Comparison - Step by Step

1console.log('start');
2
3setTimeout(() => {
4 console.log('setTimeout');
5}, 0);
6
7setImmediate(() => { // Node.js only
8 console.log('setImmediate');
9});
10
11Promise.resolve()
12 .then(() => {
13 console.log('promise');
14 });
15
16process.nextTick(() => { // Node.js only
17 console.log('nextTick');
18});
19
20console.log('end');
Starting execution. Both environments push the Global Context onto the stack.
🌐BrowserExecuting
main()
global context
- empty -
- empty -
Node.jsExecuting
nextTick
microtask
timers
poll
check
close
main()
global context
- empty -
- empty -
- empty -
- empty -

Browser Order

1.start
2.end
3.promise
4.setTimeout

Node.js Order

1.start
2.end
3.nextTick
4.promise
5.setTimeout
6.setImmediate