Member-only story

Promises in JavaScript

A Shift from Callbacks

Patrick Karsh
4 min readFeb 4, 2024
Please return my request, I promise I will resolve it.

In the realm of JavaScript, handling asynchronous operations is a critical aspect of creating responsive, non-blocking web applications. Asynchronous JavaScript operations allow the program to continue running while waiting for operations like fetching data from a server, reading files, or executing time-consuming tasks. Historically, callbacks were the primary method for managing these operations. However, with the introduction of Promises in ES6 (ECMAScript 2015), JavaScript developers have been equipped with a more powerful and flexible tool to work with asynchrony. This article explores how Promises work in JavaScript and how they differ from traditional callback functions.

What are Callbacks?

A callback is a function passed into another function as an argument to be executed later. Callbacks have been used in JavaScript to handle asynchronous operations like events, server requests, or timers. While effective for simple tasks, callbacks can lead to complex, hard-to-maintain code structures known as “callback hell” or “the pyramid of doom,” especially when multiple asynchronous operations depend on each other.

--

--

Patrick Karsh
Patrick Karsh

Written by Patrick Karsh

NYC-based Ruby on Rails and Javascript Engineer leveraging AI to explore Engineering. https://linktr.ee/patrickkarsh

No responses yet