Skip to content
BENIBIX Learn

Promise vs Async/Await

People think async and await replace promises for good, and they do not. An async function still hands back a promise. The word await is a tidier way to wait for one, so the code reads from top to bottom. Under the hood it is the same promise. The then and catch calls just turn into plain lines inside a try and catch.

Development🧭 Programming Paradigms

Promise (JavaScript)

An object for a result not ready yet. It ends in a value or an error.

A promise is an object that stands for a result that is not ready yet. It starts as pending, then ends as fulfilled with a value or rejected with an error. You attach what to do next with then, and what to do on failure with catch. Promises can be chained, so steps read in order instead of nesting. Other languages call the same idea a future.

Example
Lucy's app calls fetch for a weather page. It gets a promise at once, and the forecast shows up when the promise is fulfilled.
Why it matters
Most modern JavaScript tools give back promises. async/await is built on top of them.
Full entry
Development🧭 Programming Paradigms

Async/Await

Async code that reads top to bottom. await waits for each result.

Async/await lets you write async code that reads like normal step-by-step code. You mark a function with async, then put await in front of a slow call. At an await, the function pauses until the result is ready, while the rest of the program keeps running. Errors are caught with a plain try and catch. JavaScript, Python, C# and Rust all have it.

Example
Emma writes const data = await fetch(url). The next line can use data, and the page never freezes while it waits.
Why it matters
It is the most common way to write async code today. It is far easier to read than chains of callbacks.
Full entry

In one line

Promise (JavaScript)
An object for a result not ready yet. It ends in a value or an error.
Async/Await
Async code that reads top to bottom. await waits for each result.