home about blog portfolio contact
← back to blog
JavaScript

Understanding async/await without losing your mind

April 2025  ·  5 min read

Asynchronous programming is one of the first real hurdles in JavaScript. Promises helped, but async/await made it genuinely readable.

What is async/await?

async/await is syntactic sugar built on top of Promises. When you mark a function as async, it always returns a Promise. Inside it, await pauses execution until the Promise resolves.

async function getData() {
  const response = await fetch("https://api.example.com/data");
  const json = await response.json();
  return json;
}

Why does this matter?

Before async/await, chaining .then() callbacks led to deeply nested, hard-to-read code. Now your async logic reads like synchronous code — top to bottom, easy to follow.

Error handling

Wrap your await calls in try/catch to handle failures cleanly:

async function getData() {
  try {
    const response = await fetch("https://api.example.com/data");
    return await response.json();
  } catch (err) {
    console.error("Failed:", err);
  }
}

That is all there is to it. Once it clicks, you will wonder how you lived without it.