We must track synchronous code, setTimeout callbacks (macrotasks), and Promise rejection handling (microtasks).
Step-by-step:
Line 01–03: Schedules a timeout at 1100 ms: logs 1 (later).
Line 04: console.log(2); → logs 2.
Lines 05–09: Construct a new Promise.
The executor runs immediately.
Inside it, another setTimeout is set for 1000 ms:
setTimeout(() = > {
reject(console.log(3));
}, 1000);
Line 09–11: .catch(() = > { console.log(4); }) attached to the promise.
Line 12: console.log(5); → logs 5.
So after all synchronous code, the console has:
The callback:
() = > {
reject(console.log(3));
}
Inside:
console.log(3) runs first , logging 3.
console.log(3) returns undefined.
Then reject(undefined) is called.
So at about 1000 ms, we log:
When the promise is rejected:
The .catch handler is scheduled as a microtask .
After the current macrotask (the timeout callback) completes, the microtask queue runs.
Thus .catch(() = > { console.log(4); }) runs shortly after, in the same 1000 ms tick.
So immediately after 3, the catch handler logs:
Now the logs in order are:
console.log(1);
Final log order:
2 (line 4, sync)
5 (line 12, sync)
3 (1000 ms timeout, then inside logs before reject)
4 (promise catch microtask after rejection)
1 (1100 ms timeout)
Concatenated: 25341.
Therefore, the correct option is:
Answer: A
Study Guide / Concept References (no links):
Event loop: call stack, macrotask queue (timers), microtask queue (promises)
setTimeout scheduling and ordering
Promise rejection, .catch, and microtasks
Evaluation order of function arguments (reject(console.log(3)))
Submit