Modern JavaScript (ES6+) for Beginners
Lesson 10 of 12 83% of course

Promises — then, catch & finally

1 · 5 min · 6/7/2026

Learn Promises — then, catch & finally in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

Promises — then, catch & finally
Lesson 10 of 12 · Part 4 — Async & Modules · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 10/12 · Read time: ~18 min · Level: Beginner · ES version: ES2015 (ES6) and above

Promises — then, catch & finally

A Promise represents work that finishes later (API call, file read, timer). ES6 standardized Promises. Node.js and browsers use them everywhere — async/await (next lesson) is built on top.

Three states

  • Pending — still running
  • Fulfilled — success, .then() runs
  • Rejected — error, .catch() runs

Creating a Promise

function wait(ms) {
  return new Promise((resolve) => {
    setTimeout(() => resolve('done'), ms);
  });
}

wait(1000).then(msg => console.log(msg));

Chaining API-style flow

fetch('https://api.example.com/courses')
  .then(res => {
    if (!res.ok) throw new Error('HTTP ' + res.status);
    return res.json();
  })
  .then(data => {
    console.log('Courses:', data.length);
  })
  .catch(err => {
    console.error('Failed:', err.message);
  })
  .finally(() => {
    console.log('Request finished');
  });
🌍 Real-world example — Verify coupon code (simulated)
function validateCoupon(code) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (code === 'LEARN50') resolve({ discount: 50 });
      else reject(new Error('Invalid coupon'));
    }, 300);
  });
}

validateCoupon('LEARN50')
  .then(({ discount }) => console.log('Saved', discount + '%'))
  .catch(err => console.log(err.message));
⚠️ Common Mistake: Forgetting to return inside .then — breaks the chain. Always return the next Promise or value.
💡 Tip: Promise.all([p1, p2]) runs promises in parallel — used when loading dashboard + user profile together.
👨‍🏫 Teaching note: Draw the Promise state diagram on board before showing async/await — students map await to .then mentally.

Continue learning

Previous: for...of, Sets & Maps Essentials

Next: async/await & Fetch API

Course home: All 12 lessons

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
Modern JavaScript (ES6+) for Beginners

On this page

Three states Creating a Promise Chaining API-style flow Continue learning
Part 1 — Modern Basics
Introduction — Why ES6+ Before Node.js & React let, const & Block Scope Arrow Functions Explained
Part 2 — Write Less Code
Template Literals & Modern Strings Destructuring — Arrays & Objects Spread & Rest Operators (...)
Part 3 — Data & Collections
Default Parameters & Object Shorthand Array Methods — map, filter, find & reduce for...of, Sets & Maps Essentials
Part 4 — Async & Modules
Promises — then, catch & finally async/await & Fetch API Modules — import/export & What to Learn Next
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details