JavaScript Interview Preparation: Priority of callback, promise, setTimeout, and process.nextTick()

Ravi Sharma
5 min readOct 9, 2023

Welcome back to this javascript interview preparation series. In this article, we will explore the priority and execution of four commonly used methods for writing asynchronous code: callbacks, promises, setTimeout, and process.nextTick().

JavaScript Main Components

The questions related to the priority of execution can be answered by investigating the event loop. Let’s recall the main components of how asynchronous JavaScript works.

JavaScript Main Components

The call stack is a LIFO (Last In, First Out) structure that stores the execution context created during the code execution. In simple words, the execution context is created every time a function is called and the call stack executes those functions.

Web APIs is the place where the async operations (setTimeout, fetch requests, promises) with their callbacks are waiting to complete. It borrows the thread from the thread pool to complete the task in the background without blocking the main thread.

--

--