Member-only story

Callbacks vs. Promises in JavaScript

The difference can be confusing — let’s clear that up

jsmanifest
Better Programming
6 min readDec 3, 2019

Photo by Robert Ruggiero on Unsplash

If you’re new to JavaScript and have a hard time trying to understand how promises work, hopefully this article will assist you in understanding them more clearly.

With that said, this article is aimed at those who are a little unsure about promises.

This post won’t be going over executing promises using async/await (although they’re the same thing functionality-wise — only that async/await is more syntactic sugar for most situations).

The What

Promises were actually out for awhile even before they were native to JavaScript. For example, two libraries that implemented this pattern before promises became native is Q and when.

So what are promises? Promises are JavaScript objects that represent an eventual completion or failure of an asynchronous operation. You can achieve results from performing asynchronous operations using the callback approach or by using promises. But there are some minor differences between the two.

Key Difference Between Callbacks and Promises

A key difference between the two is when using the callback approach, we’d normally just pass a callback into a…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

jsmanifest
jsmanifest

Written by jsmanifest

Team Lead Front End Developer for a TeleMedicine Company. Follow and Join Me on my Adventures. https://jsmanifest.com

Responses (6)

Write a response

Just stumbled upon this article. The first callback example code doesn't seem to make sense.
```
function getMoneyBack(money, callback) {
if (typeof money !== 'number') {
callback(null, new Error('money is not a number'))
} else {
callback(money)
}
}
const…

we’d have to ask why using the callback approach just wasn’t enough for the majority of JavaScript developers out there.

Faced this question and came here