Promise chaining
📖 Scenario: Imagine you are ordering a pizza online. First, you select the pizza, then you pay for it, and finally, you get a confirmation message. Each step happens one after the other.
🎯 Goal: You will create three functions that return promises for each step: selectPizza, payForPizza, and confirmOrder. Then, you will chain these promises together to show the full order process.
📋 What You'll Learn
Create a function called
selectPizza that returns a promise resolving to the string 'Pizza selected'.Create a function called
payForPizza that takes a string and returns a promise resolving to 'Payment done'.Create a function called
confirmOrder that takes a string and returns a promise resolving to 'Order confirmed'.Chain the three functions using
.then() to run them one after another.Print the final confirmation message.
💡 Why This Matters
🌍 Real World
Promise chaining is used in real life when you need to do tasks one after another that take time, like loading data from the internet or processing payments.
💼 Career
Understanding promise chaining is important for web developers to handle asynchronous operations smoothly, improving user experience and app reliability.
Progress0 / 4 steps