Ighmaz β—’β—€
Ighmaz β—’β—€

@ighmaz_js

6 Tweets 7 reads Apr 08, 2022
JavaScript Promise Explained ⚑️
A πŸ§΅πŸ‘‡
Promises are used to handle asynchronous operations in JavaScript.
They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code.
The most common use case of Promise is fetching data from a REST API
The fetch API from JavaScript returns a Promise because the HTTP request can take a lot of time and then we can call functions depending on whether the request succeeds or failed
A Promise is in one of these states:
⭐️ pending: initial state, neither fulfilled nor rejected.
⭐️ fulfilled: meaning that the operation was completed successfully.
⭐️ rejected: meaning that the operation failed.
Promise Syntax:
Benefits of Promises -
⭐️Improves Code Readability
⭐️ Better handling of asynchronous operations
⭐️Better flow of control definition in asynchronous logic
⭐️ Better Error Handling
That's it Guys
Thank you for reading this πŸ™
If you liked this thread, make sure to:
Follow me
@ighmaz_js
and retweet this!

Loading suggestions...