<aside> 💡 프로미스가 생성된 시점에는 아직 알려지지 않은 값을 위한 대리자 객체
</aside>
const myFirstPromise = new Promise((resolve, reject) => {
// We call resolve(...) when what we were doing asynchronously was successful, and reject(...) when it failed.
// In this example, we use setTimeout(...) to simulate async code.
// In reality, you will probably be using something like XHR or an HTML API.
setTimeout(() => {
resolve("Success!"); // Yay! Everything went well!
}, 250);
});
myFirstPromise.then((successMessage) => {
// successMessage is whatever we passed in the resolve(...) function above.
// It doesn't have to be a string, but if it is only a succeed message, it probably will be.
console.log(`Yay! ${successMessage}`);
});
Pending | Initial state, neither fulfilled nor rejected. |
---|---|
Fulfilled | Meaning that the operation was completed successfully. |
Rejected | Meaning that the operation failed. |