Modern JavaScript (ES6+) for Beginners
Lesson 11 of 12 92% of course

async/await & Fetch API

0 · 5 min · 6/7/2026

Learn async/await & Fetch API in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

async/await & Fetch API
Lesson 11 of 12 · Part 4 — Async & Modules · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 11/12 · Read time: ~20 min · Level: Beginner · ES version: ES2015 (ES6) and above

async/await & Fetch API

async/await makes asynchronous code read like normal top-to-bottom code. The fetch API loads data from URLs — used in browsers and Node (native fetch since Node 18). This is how React apps load data and how Node servers call other APIs.

async function basics

async function loadCourses() {
  try {
    const res = await fetch('/api/courses');
    if (!res.ok) throw new Error('Failed to load');
    const courses = await res.json();
    return courses;
  } catch (err) {
    console.error(err);
    return [];
  }
}

await pauses inside an async function until the Promise completes. It does not block the whole browser — other code still runs.

Parallel requests

async function loadDashboard(userId) {
  const [profile, orders] = await Promise.all([
    fetch(`/api/users/${userId}`).then(r => r.json()),
    fetch(`/api/orders?user=${userId}`).then(r => r.json())
  ]);
  return { profile, orders };
}
🌍 Real-world example — Mark lesson complete (Toolliyo-style)
async function markLessonComplete(slug, csrfToken) {
  const res = await fetch('/tutorials/api/progress', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ slug, action: 'complete', csrfToken })
  });
  const data = await res.json();
  return data.success;
}

Same pattern in React: async handler → fetch → update UI state.

⚠️ Common Mistake: Using await inside a non-async function — syntax error. Mark the function async or use .then().
💡 Tip: Always wrap await in try/catch in production — network fails, servers return 500, users go offline.
👨‍🏫 Teaching note: Demo: fetch a public JSON API (e.g. jsonplaceholder) in browser console with await — instant engagement.

Continue learning

Previous: Promises — then, catch & finally

Next: Modules — import/export & What to Learn Next

Course home: All 12 lessons

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
Modern JavaScript (ES6+) for Beginners

On this page

async function basics Parallel requests Continue learning
Part 1 — Modern Basics
Introduction — Why ES6+ Before Node.js & React let, const & Block Scope Arrow Functions Explained
Part 2 — Write Less Code
Template Literals & Modern Strings Destructuring — Arrays & Objects Spread & Rest Operators (...)
Part 3 — Data & Collections
Default Parameters & Object Shorthand Array Methods — map, filter, find & reduce for...of, Sets & Maps Essentials
Part 4 — Async & Modules
Promises — then, catch & finally async/await & Fetch API Modules — import/export & What to Learn Next
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details