Skip to content
Guest
Learn JavaScript · Course Syllabus Show lessons
Async & Modern JS · 10 min read · Beginner

Async/Await, Promises & JSON

Handle asynchronous operations cleanly with async/await, try/catch error handling, and loading states.

What you'll learn

  • Await Promises cleanly inside an async function
  • Handle errors gracefully using try / catch / finally
  • Display clear loading, success, and error UI states

Fetching data from an API takes time. JavaScript handles slow operations asynchronously using Promises so the browser never freezes while waiting.

Clean async / await Pattern

async function loadLesson() {
  try {
    const response = await fetch('/api/lesson.json');
    if (!response.ok) throw new Error('Failed to load');
    const data = await response.json();
    return data;
  } catch (err) {
    console.error(err.message);
  }
}

Try It Yourself

Click Fetch Next Tip (or Simulate Error) to see async/await with loading and try/catch/finally states in action:

Async Data Loader with try/catch/finally
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. Which block in try / catch / finally always runs whether the Promise succeeds or fails?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind