CodeZettaInterview Hub

Node.js · Event Loop · Junior · Code Output

setTimeout(fn, 0) vs setImmediate(fn) — which runs first?

Short Interview Answer

It depends on context: inside an I/O callback, setImmediate usually runs first; in main module, ordering can vary.

Detailed Explanation

Don't rely on either for precise sequencing — use explicit control flow. This question tests whether candidates know 'it depends' rather than a false absolute.

Did you know this answer?