Frontend development

Stage 2 · Lesson 7 of 10

Promises and async/await

JavaScript and the browser

Anything that takes time in the browser, such as a network request or a timer, is . Your code starts it and carries on, and the result arrives later. stand for that future result.

Each one starts pending, then is either fulfilled with a value or rejected with an error. and await let you write this as straight line code: const res = await fetch(url) pauses that one function, not the whole page. Handle failure with try and catch.

Run independent requests together with Promise.all, instead of awaiting them one after another. The two classic traps are forgetting await, so you get a promise instead of data, and having no catch, so failures vanish silently.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    Guided beginner course on the language core, with quizzes after every chapter

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch

Practise

  • Thirty small browser projects with no framework to hide behind

  • Free JavaScript curriculum exercises for daily reps on the language core

Keep handy

  • JavaScript and Web API reference, including fetch, the DOM and events

Also worth your time

Mark this stage as not done?