codemarch
codemarch

@codemarch

11 Tweets 4 reads Sep 19, 2022
JavaScript Promise and Promise Chaining
The Complete Guide:
Thread 🧵
📌In JavaScript, a promise is a good way to handle asynchronous operations. It is used to find out if the asynchronous operation is successfully completed or not.
📌A promise may have one of three states.
1⃣Pending
2⃣Fulfilled
3⃣Rejected
📌Create a Promise.
➡️To create a promise object, we use the Promise() constructor.
➡️The Promise() constructor takes a function as an argument. The function also accepts two functions resolve() and reject().
➡️If the promise returns successfully, the resolve() function is called. And, if an error occurs, the reject() function is called.
📌JavaScript Promise Chaining.
➡️Promises are useful when you have to handle more than one asynchronous task, one after another. For that, we use promise chaining.
➡️You can perform an operation after a promise is resolved using methods then(), catch() and finally().
📌JavaScript then() method.
➡️The then() method is used with the callback when the promise is successfully fulfilled or resolved.
📌JavaScript Promise Versus Callback.
➡️Promises are similar to callback functions in the sense that they both can be used to handle asynchronous tasks.
📌Their differences can be summarized in the following points:
➡️JavaScript Promise
📝The syntax is user-friendly and easy to read.
📝Error handling is easier to manage.
➡️JavaScript Callback
📝The syntax is difficult to understand.
📝Error handling may be hard to manage.
📌JavaScript Promise Methods.
➡️There are various methods available to the Promise object.
To learn more about promises , visit rli.to
If you enjoyed reading this thread, please do the following:
1. Like the thread❤️
2. Retweet the first tweet.🔃
3. Follow me and enable notifications: ✅
@CodeMarch
Thank you for reading all the way through.
✨ JavaScript for Starters: The Complete Guide ✨
➱ JavaScript Roadmap 2022
➱ JavaScript Fundamentals with Exp.
➱ 50+ Programs to practice with Soln.
➱ 50+ Project Ideas
➱ 25+ Projects Code
Grab it NOW.

Loading suggestions...