Because an error thrown in an async path that is not caught becomes an unhandled rejection. Always use try/catch in async functions, or .catch on promises, so errors are handled and do not crash the process.
Common Async Timing Mistakes in Node.js Code
Why do unhandled rejections happen from async paths?
The answer
More FAQs in Common Async Timing Mistakes in Node.js Code
Because it runs on the next event loop tick, not immediately. Code after it may run first, and promise microtasks run before it. Assuming it is instant causes bugs when code relies on specific timing.
Forgetting that microtasks (promise callbacks) run before macrotasks (setTimeout, I/O callbacks). If your code assumes the order is the order you wrote it, you get bugs. Understand the order: sync, nextTick, promises, then macrotasks.
Because nextTick runs before promises, both before macrotasks. If you use nextTick expecting it to run after promises, you get bugs. It is Node.js-specific and runs first among microtasks.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.