setInterval only pushes functions into this queue, to be run at specified time.
This is why you do not want to run a blocking function in JS.
Callbacks passed to functions such as
This hidden logic schedules the insertion of callbacks on job queues, at appropriate times (eg. after an interval has elapsed). When a job associated with a callback reaches the front of the relevant job queue, and when the executing thread is available to service it, the job is removed from the queue, a stack frame (aka execution context) is instantiated for it, pushed onto the call stack, and execution begins.
The logic for asynchronous functions such as
requestAnimationFrame are defined in other specifications (eg. W3C/WHATWG), and implemented by host applications (eg. a web browser or a NodeJS instance). These functions are not defined by the ECMAScript specification.
Asynchronous promise behavior, on the other hand, is specified within the ECMAScript specification.
It was coded to remember it. 🙂
Check out “What the heck is the event loop?” conference talk on YouTube for maybe one of the best explanations out there: