Sitemap
DataDrivenInvestor

empowerment through data, knowledge, and expertise. Join DDI community at https://join.datadriveninvestor.com

Follow publication

Member-only story

Javascript Promises— Is There a Better Approach?

5 min readDec 8, 2022

--

Photo by Pixabay

A promise is an object returned by an asynchronous function, which represents the current state of the operation. At the time the promise is returned to the caller, the operation often isn’t finished, but the promise object provides methods to handle the eventual success or failure of the operation. — MDN Web Docs

We use promises every day in JavaScript and its great… but they have their issues. On the good side, they are non-blocking and thus, fast. However, dealing with them can be cumbersome.

We often have to wait for a function to complete to get its “callback” and proceed to the next task. There are no guarantees or control flow for when a promise will complete.

Additionally, we are working with unknown error types, a high likelihood of unchecked exceptions, and more. Promises co-mingle rejected promises and unintended runtime exceptions. But thankfully, there are alternatives!

In order to understand promises and their alternatives, we need to understand the different types of programming:

  • Functional programming is when we build software by composing functions while avoiding shared states, mutable data, and side…

--

--

DataDrivenInvestor
DataDrivenInvestor

Published in DataDrivenInvestor

empowerment through data, knowledge, and expertise. Join DDI community at https://join.datadriveninvestor.com

Anisha Jain
Anisha Jain

Written by Anisha Jain

Ex-Tesla Senior Software Engineer, and writer at NYC Design, and Data Driven Investor Publications on Medium. Former writer at Lyft Engineering Blog.