Tutorials Modern JavaScript (ES6+) for Beginners

async/await & Fetch API

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.

On this page
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

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain JavaScript in the context of Modern JavaScript (ES6+) for Beginners.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. How to structure your answer (60–90 seconds) Define JavaScript i…
Mid Detailed
What are common mistakes teams make with Components when using Modern JavaScript (ES6+) for Beginners?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Components in plain language…
Senior Detailed
How would you debug a production issue related to State in a Modern JavaScript (ES6+) for Beginners application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define State in plain language for…
Mid Detailed
Compare two approaches to API integration—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define API integration in plain lan…
Junior Detailed
Describe a real-world scenario where Performance mattered in a Modern JavaScript (ES6+) for Beginners project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Performance in plain languag…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Modern JavaScript (ES6+) for Beginners
Course syllabus
Part 1 — Modern Basics
Part 2 — Write Less Code
Part 3 — Data & Collections
Part 4 — Async & Modules
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