Middle
/** * What will be printed to the console and why */ const a = () => console.log('a'); const b = () => setTimeout(() => console.log('b'), 0); const c = () => Promise.resolve().then(() => console.log('c')); a(); b(); c();
sobes.tech AI
Answer from AI
The console will output in the following order:
a
c
b
Explanation:
a()— a synchronous function that immediately outputs 'a'.b()— callssetTimeoutwith a delay of 0, which places the callback in the macro task queue; it will execute after all microtasks and the current call stack.c()— creates a promise that resolves immediately, and its.thenplaces the callback in the microtask queue.
The JavaScript event loop first executes all synchronous operations, then microtasks (promises), and only then macro tasks (setTimeout). Therefore, the output order is 'a', then 'c', then 'b'.