Suggest improvements


Promises make it easier to write asynchronous code compared to using callbacks, and many libraries and Web APIs return promises for async operations, like fetch():

loadUsers() {
  fetch('/api/users').then((response) => {
    return response.json();
  }).then((data) => {
    this.users = data;
  }).catch((ex) => {
    console.error('Error fetching users', ex);

We can also create our own promises using the Promise constructor, though we should rarely need to do this as it is almost always better to use a promise from an API like fetch() if possible:

computeAnswerToLifeTheUniverseAndEverything() {
  return new Promise((resolve, reject) => {

Promises look simple at first but are complex and powerful in practice. Take care to avoid common anti-patterns with their usage.