Volunteering
  • Welcome!
  • Code Review
    • Task Description
    • How to review an entire repo on github
  • Tech Tutorials
    • Task Description
    • Topics
      • Template
      • Async await (Javascript)
      • Clean code
      • Top 5 tips for a junior developer
      • Chrome debugging
  • Examples
    • Bonsai Project
Powered by GitBook
On this page
  • Task
  • Learning objectives:
  • Students will already:
  • Resources you can use:
  • Detailed Notes:
  1. Tech Tutorials
  2. Topics

Async await (Javascript)

PreviousTemplateNextClean code

Last updated 3 years ago

Task

Learning objectives:

Most students should:

  • Know how to write code using async/await

  • Understand how the async/await keywords makes working with promises simpler

  • Demonstrate how to convert from .then()/.catch functions to using async await

Students will already:

  • Have had roughly 65 hours of tuition and practise with javascript

  • Understand how to use promises using the .then()/.catch() functions

Resources you can use:

You can use these resources to help build your lesson plan

Detailed Notes:

We recommend you use visual studio code as your IDE. This is the IDE students are familiar with.

Explain what async is and show an async function

async function returnNumber()
{
  return 5;
}

returnNumber().then(console.log);

Explain the await keyword and how to use in an async function

async function getDataFromAPI()
{ 
  data = await fetch('http://example.com/movies.json') 
}

Show how to rewrite a function using async await instead of then/catch

See this example:

https://dev.to/lydiahallie/javascript-visualized-promises-async-await-5gke
https://javascript.info/async-await
https://www.freecodecamp.org/news/learn-promise-async-await-in-20-minutes/
https://github.com/changetocoding/WebLessonPlan/blob/main/Lesson18-AsyncAwait.md
https://javascript.info/async-await#rewrite-using-async-await