Tutorials Logic, IN info@tutorialslogic.com

JavaScript Promises then, catch, async/await: Tutorial, Examples, FAQs & Interview Tips

JavaScript Promises then, catch, async/await

JavaScript Promises then, catch, async/await is an important JavaScript topic because it appears in real projects, debugging sessions, and interviews. Learn the meaning first, then connect it to a small working example so the rule does not stay abstract.

For this page, focus on what problem JavaScript Promises then, catch, async/await solves, where developers usually make mistakes, and how to verify the result. The audit note for this lesson was: under 650 content words; limited checklist/practice/mistake/FAQ notes .

A strong understanding of JavaScript Promises then, catch, async/await should include syntax, behavior, one realistic use case, one failure case, and one quick way to check your work with tools or output.

JavaScript Promises then catch async await should be studied as a practical JavaScript lesson, not as a label. Start by naming the input, the rule that changes the input, and the result a learner should be able to predict after reading the page.

In the javascript > promises page, the notes should connect the definition with a working scenario, a mistake that beginners actually make, and the exact check that proves the fix. That makes the topic useful for coding, debugging, and interview revision.

What is a Promise?

A Promise is a JavaScript object that represents the eventual result of an asynchronous operation. Instead of passing callbacks into a function, a promise lets you attach handlers to the future success or failure of that operation. This makes async code much easier to read and reason about.

A Promise is always in one of three states:

Once a promise is fulfilled or rejected it is settled and its state never changes again.

  • Pending - the initial state; the operation has not completed yet.
  • Fulfilled - the operation completed successfully and the promise has a resolved value.
  • Rejected - the operation failed and the promise has a reason (error).

Creating a Promise

Creating a Promise
const promise = new Promise((resolve, reject) => {
  const success = true;

  if (success) {
    resolve('Operation succeeded!');
  } else {
    reject(new Error('Operation failed!'));
  }
});

promise
  .then(result => console.log(result))   // Operation succeeded!
  .catch(error => console.error(error));  // only runs on rejection

Chaining Promises

Each .then() returns a new promise, which allows you to chain multiple async steps in a readable sequence. The value returned from one .then() is passed as the argument to the next.

Promise Chaining

Promise Chaining
fetch('https://api.example.com/user/1')
  .then(response => response.json())       // parse JSON
  .then(user => {
    console.log(user.name);
    return fetch(`/api/posts?userId=${user.id}`);
  })
  .then(response => response.json())
  .then(posts => console.log(posts))
  .catch(error => console.error('Error:', error))
  .finally(() => console.log('Done'));     // always runs

Promise.all() - Run in Parallel

Promise.all() takes an array of promises and returns a single promise that resolves when all of them resolve, or rejects as soon as any one of them rejects. Use it when tasks are independent and can run simultaneously.

Promise.all()

Promise.all()
const p1 = fetch('/api/users').then(r => r.json());
const p2 = fetch('/api/posts').then(r => r.json());
const p3 = fetch('/api/comments').then(r => r.json());

Promise.all([p1, p2, p3])
  .then(([users, posts, comments]) => {
    console.log(users, posts, comments);
  })
  .catch(err => console.error('One failed:', err));

Promise.allSettled(), race(), any()

JavaScript provides several other static methods for handling multiple promises:

  • Promise.allSettled() - waits for all promises to settle (fulfilled or rejected); never rejects. Returns an array of result objects.
  • Promise.race() - resolves or rejects as soon as the first promise settles.
  • Promise.any() - resolves as soon as the first promise fulfills; rejects only if all reject.

allSettled / race / any

allSettled / race / any
const slow = new Promise(res => setTimeout(() => res('slow'), 2000));
const fast = new Promise(res => setTimeout(() => res('fast'), 500));
const fail = Promise.reject(new Error('failed'));

// allSettled - never rejects
Promise.allSettled([slow, fast, fail]).then(results => {
  results.forEach(r => console.log(r.status, r.value ?? r.reason));
});

// race - first to settle wins
Promise.race([slow, fast]).then(v => console.log(v)); // 'fast'

// any - first to FULFILL wins
Promise.any([fail, fast]).then(v => console.log(v));  // 'fast'

Error Handling in Promises

Always attach a .catch() at the end of a promise chain to handle any rejection that bubbles up. The .finally() handler runs regardless of success or failure - useful for cleanup like hiding a loading spinner.

Error Handling

Error Handling
function loadUser(id) {
  return fetch(`/api/users/${id}`)
    .then(res => {
      if (!res.ok) throw new Error(`HTTP ${res.status}`);
      return res.json();
    });
}

loadUser(42)
  .then(user => console.log('Loaded:', user.name))
  .catch(err => console.error('Failed:', err.message))
  .finally(() => console.log('Request complete'));

Detailed Learning Notes for JavaScript Promises then, catch, async/await

When studying JavaScript Promises then, catch, async/await, separate three things: the concept, the syntax, and the situation where it is useful. This prevents the lesson from becoming a list of commands with no practical meaning.

In JavaScript, JavaScript Promises then, catch, async/await becomes easier when you build a tiny example first, then increase complexity. Add one realistic input, one invalid or boundary input, and one explanation of why the result changes.

  • Identify the main problem this topic solves.
  • Write the smallest possible working example.
  • Change one input or option and observe the result.
  • Note the mistake that would break the example.

JavaScript Promises then catch async await Java review example

JavaScript Promises then catch async await Java review example
class JavaScriptPromisesthencatchasyncawaitReview {
    public static void main(String[] args) {
        String state = "ready";
        System.out.println("JavaScript Promises then catch async await: " + state);
    }
}

JavaScript Promises then catch async await guard example

JavaScript Promises then catch async await guard example
String value = null;
if (value == null) {
    System.out.println("JavaScript Promises then catch async await: handle the missing value before continuing");
}
Key Takeaways
  • Explain the purpose of JavaScript Promises then, catch, async/await before memorizing syntax.
  • Trace the exact call expression and confirm which value reached the parentheses.
  • Test one normal case, one edge case, and one mistake case for JavaScript Promises then, catch, async/await.
  • Write down why the value is not callable and what should hold the function instead.
  • Connect JavaScript Promises then, catch, async/await to a real project scenario instead of treating it as an isolated definition.
Common Mistakes to Avoid
WRONG Calling a value before checking whether it actually holds a function reference.
RIGHT Trace the variable assignment, the property lookup, and the actual call expression.
Most beginner errors come from skipping the behavior behind the syntax.
WRONG Memorizing JavaScript Promises then catch async await without the situation where it is useful.
RIGHT Connect JavaScript Promises then catch async await to a concrete JavaScript task.
Purpose makes syntax easier to recall.
WRONG Testing JavaScript Promises then catch async await only with the perfect input.
RIGHT Include empty, missing, duplicate, incompatible, or failed cases when relevant.
Real bugs usually appear outside the perfect path.
WRONG Memorizing JavaScript Promises then catch async await without the situation where it is useful.
RIGHT Connect JavaScript Promises then catch async await to a concrete JavaScript task.
Purpose makes syntax easier to recall.

Practice Tasks

  • Modify the example so it guards with `typeof` or uses the correct method name.
  • Write one mistake related to JavaScript Promises then, catch, async/await, then fix it and explain the fix.
  • Summarize when to use JavaScript Promises then, catch, async/await and when another approach is better.
  • Write a small example that uses JavaScript Promises then catch async await in a realistic JavaScript scenario.
  • Change one important value in the JavaScript Promises then catch async await example and predict the result first.

Frequently Asked Questions

The common mistake is memorizing syntax without understanding when the behavior changes or fails.

Remember the problem it solves in JavaScript, then attach the syntax or steps to that problem.

You can predict the result of a small example, explain a failure case, and choose it over a nearby alternative for a clear reason.

They often copy the syntax but skip the state, input, dependency, selector, route, type, or configuration that controls the behavior.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.