Glossary

Promise / async-await

A Promise is an object representing the result of an async operation: pending, fulfilled, or rejected. async/await is syntactic sugar for working with Promises more readably.

Promise

fetch('/api/users')
  .then(res => res.json())
  .then(users => console.log(users))
  .catch(err => console.error(err));

async/await

async function getUsers() {
  try {
    const res = await fetch('/api/users');
    const users = await res.json();
    console.log(users);
  } catch (err) {
    console.error(err);
  }
}

Promise.all vs Promise.allSettled