-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecution_precedence.js
More file actions
57 lines (43 loc) · 1.02 KB
/
execution_precedence.js
File metadata and controls
57 lines (43 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
TODO: describe the order of console's logs
*/
console.log("main thread: normal log");
for(let i = 0; i < 5; i++) {
console.log('main thread: for 1 indice = ' + i);
}
let count = 0;
// run after setTimeOut
const int = setInterval(() => {
if (count > 3) {
clearInterval(int);
}
console.log("macrotask queue: setInterval");
count++;
}, 0);
setTimeout(() => {
console.log("macrotask queue: setTimeout");
}, 0);
(new Promise(resolve => resolve())).then(() => {
console.log("microtask queue: promise");
});
// last executed
setImmediate(() => {
console.log("macrotask queue: setImmediate");
});
for(let i = 0; i < 5; i++) {
console.log('main thread: for 2 indice = ' + i);
}
// runs before promise and
process.nextTick(() => {
console.log("microtask queue: 5 next tick");
});
console.log("main thread: normal log 6");
a();
(function () {
console.log('main thread: immediate function')
})();
a();
function a() {
console.log('main thread: function a')
}
console.log("main thread: normal log 7");