Part 2: How Promises interact with JavaScript’s Call Stack and Event Loop

The animated visualizations in this post were created with https://jsv9000.app — a tool designed to help you visualize and learn about the Event Loop.

In the previous post, we learned about JavaScript’s Call Stack and Event Loop. We worked through an example that used setTimeout() to break a long-running synchronous function into a series of short tasks. But why did we choose setTimeout()? Could we have used Promise.resolve() instead? After all, Promises are supposed to be asynchronous, and all async JavaScript works by enqueuing tasks in the Event Loop.

Let’s try it!

setTimeout() vs. Promise.resolve()

We’ll use the webpage we created in part…


Part 1: The Call Stack, the Event Loop

The animated visualizations in this post were created with https://jsv9000.app — a tool designed to help you visualize and learn about the Event Loop.

I’ve been writing JavaScript for awhile. I’ve written web services with Express, web apps with React, mobile apps with React Native, and I’ve authored libraries, such as pdf-lib.

Recently, while working on pdf-lib, I found myself dealing with some long running synchronous code. I had optimized this code to run as fast as possible. …


Deno is an exciting new runtime for JavaScript and TypeScript. It was created by the original author of Node and corrects some key mistakes in Node’s design. Version 1.0 of Deno was announced just 5 days ago on May 13th, 2020.

Many developers (myself included) are very excited about Deno and the potential it has to change the JavaScript ecosystem for the better. Deno strives for compatibility with standard web APIs. This means that Deno does not resolve dependencies via a centralized repository such as NPM. Instead, dependencies must be imported via fully qualified URLs. In addition, Deno does not…

Andrew Dillon

Senior Software Engineer at https://qdivision.io/. Author and maintainer of https://pdf-lib.js.org/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store