developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises
5 Users
0 Comments
63 Highlights
1 Notes
Top Highlights
ation. At the time the promise is returned to the caller, the operation often isn't finished, but the promise object provides methods to handle the eventual success or failure of the operation.
A promise is an object returned by an asynchronous function, which represents the current state of the operation
then() itself returns a promise
Inside an async function, you can use the await keyword before a call to a function that returns a promise. This makes the code wait at that point until the promise is settled, at which point the fulfilled value of the promise is treated as a return value, or the rejected value is thrown
all
If you add catch() to the end of a promise chain, then it will be called when any of the asynchronous function calls fails.
First, a promise can be in one of three states:
pending
fulfilled
rejected
async and await
Adding async at the start of a function makes it an async function
Inside an async function, you can use the await keyword before a call to a function that returns a promise.
completed with the result of the function passed to it
what "succeeded" or "failed" means here is up to the API
pending: the promise has been created, and the asynchronous function it's associated with has not succeeded or failed yet
then() handler
fetch() API
fulfilled: the asynchronous function has succeeded. When a promise is fulfilled, its then() handler is called
rejected: the asynchronous function has failed. When a promise is rejected, its catch() handler is called
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.