Promises in JavaScript are used to manage asynchronous operations.
Promises are often used for tasks that take a while to finish. For example, fetching data from an API, reading a file from the server, or performing a time-consuming operation.
Promises are often used for tasks that take a while to finish. For example, fetching data from an API, reading a file from the server, or performing a time-consuming operation.
Promises states:
β§ Fulfilled - If it succeeds, the operation is complete.
β§ Rejected - If an error occurs, the procedure will produce a rejected state.
β§ Pending - Process is still in progress.
β§ Settled - Has fulfilled or rejected.
β§ Fulfilled - If it succeeds, the operation is complete.
β§ Rejected - If an error occurs, the procedure will produce a rejected state.
β§ Pending - Process is still in progress.
β§ Settled - Has fulfilled or rejected.
Promises are used for fetching data, etc. When dealing with promises, you typically deal with the response rather than creating them.
Itβs important to understand that after handling a promiseβs resolved value with the `then` method, you cannot call it again on the same promise.
Instead, you might prefer to handle multiple promises at once using `Promise.all` and then wait for each one to resolve before taking further action.
Promise.all
To handle multiple promises, you can use`Promise.all` method.
It takes an array of promises as arguments and returns one promise that is resolved once every promise in the input has been resolved.
It is rejected if any promise in the input is rejected.
To handle multiple promises, you can use`Promise.all` method.
It takes an array of promises as arguments and returns one promise that is resolved once every promise in the input has been resolved.
It is rejected if any promise in the input is rejected.
Next, read about async/await here:
That's it for now. Thank you for reading!
If you found it helpful, like and retweet the first tweet and follow @ishratUmar18 for more awesome content.
If you found it helpful, like and retweet the first tweet and follow @ishratUmar18 for more awesome content.
Loading suggestions...