Junior JavaScript

What is async / await?

Syntactic sugar over Promises for cleaner asynchronous code.

async function fetchData() {

try {

const res = await fetch('/api/data');

const data = await res.json();

console.log(data);

} catch (err) { console.error(err); }

More from JavaScript Tutorial

All questions for this course