Skip to main content

Asynchronous programs

JavaScript Async Await: Promises, Errors, and Concurrency

Async and await make promise-based code easier to read, but reliable applications still need explicit failure, concurrency, cancellation, and user-interface models.

JavaScriptbeginner4 min readAsynchronous JavaScript

Learning overview

Estimated time
4 minutes
Difficulty
Beginner
Prerequisites
No prior experience required
Learning outcome
Explain javascript using a clear mental model · Apply javascript in practical JavaScript work
Last updated
July 18, 2026

Start with the promise model

An async function always returns a promise. Await pauses that function until the awaited promise settles; it does not block the entire JavaScript runtime. Rejection behaves like a thrown error at the await expression.

load-course.js
async function loadCourse(slug, signal) {
  const response = await fetch(`/api/courses/${encodeURIComponent(slug)}`, { signal });
  if (!response.ok) {
    throw new Error(`Request failed with ${response.status}`);
  }
  return response.json();
}

Handle errors and cancellation separately

Fetch rejects for network failures and cancellation, but ordinary HTTP errors still produce responses. Check response.ok. Abort obsolete requests and avoid presenting an intentional abort as a user-facing failure.

request-state.js
const controller = new AbortController();

try {
  renderLoading();
  const course = await loadCourse("javascript", controller.signal);
  renderCourse(course);
} catch (error) {
  if (error.name !== "AbortError") renderError("Could not load the course.");
} finally {
  renderNotLoading();
}

Choose sequential or concurrent execution

Await independent requests together with Promise.all so their latency overlaps. Keep sequential awaits when one operation depends on the previous result or when ordering is a requirement.

concurrent.js
const [course, progress] = await Promise.all([
  fetchCourse(courseId),
  fetchProgress(courseId),
]);

renderDashboard({ course, progress });

Model every visible state

A production interface needs idle, loading, success, empty, failure, and often stale or retrying states. Disable duplicate submissions only when appropriate and keep status updates accessible to assistive technologies.

Frequently asked questions

Does await block JavaScript?

It suspends the current async function and schedules its continuation. Other queued work can run while the awaited promise is pending.

When should I use Promise.all?

Use it for independent promises that may run concurrently and should fail as one operation. Use allSettled when every outcome must be collected.

Why does fetch not reject for a 404 response?

Fetch fulfilled its network operation and returns a Response. Your code must inspect response.ok or status and decide whether the HTTP result is acceptable.

Topic graph

A taxonomy-generated path through this subject.

  1. JavaScript
  2. Asynchronous JavaScript
  3. javascript
  4. async-await
  5. promises
  6. fetch
  7. What Is JavaScript in Programming?
  8. Learn JavaScript: From Fundamentals to Web Applications
  9. JavaScript Tutorial: Build a Filterable Task List

Recommended automatically from shared technologies, topics, intent, and difficulty.

Hand-picked companion pages that deepen this topic.

Your next steps

Continue learning

  1. 1glossaryWhat Is JavaScript in Programming?
  2. 2guidesLearn JavaScript: From Fundamentals to Web Applications
  3. 3guidesJavaScript Tutorial: Build a Filterable Task List
  4. 4cheatsheetsJavaScript Cheatsheet: Syntax, Collections, DOM, Async