This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for JavaScript Quiz on BFE.dev
47. Promise Order II
The output by console.log will be:
1
4
6
13
8
9
11
10
12
Uncaught 5
2
3
Explanation:
console.log(1)
outputs1
.console.log(4)
outputs4
.reject(5)
rejects the Promise with a value of5
.console.log(6)
outputs6
..catch(() => console.log(8))
catches the rejection of the Promise and outputs8
..then(() => console.log(9))
executes after the Promise is rejected and outputs9
..then(() => console.log(11))
executes after the previous.then()
and outputs11
..catch(() => console.log(10))
catches the rejection of the previous.then()
and outputs10
..then(() => console.log(11))
executes after the previous.catch()
and outputs11
..then(console.log)
executes after the previous.then()
and outputsundefined
(the value returned byconsole.log()
)..finally(() => console.log(12))
executes after all other Promise-related code and outputs12
.console.log(13)
outputs13
.setTimeout(() => { console.log(2) }, 10)
outputs2
after a delay of 10 milliseconds.setTimeout(() => { console.log(3) }, 0);
queues the callback to output3
, but it is executed after all other code, including the Promise-related code, so it outputs3
after everything else is done.Uncaught 5
is not output byconsole.log()
, but is an Uncaught Promise rejection with a value of5
.