pending
Initial state before the result is known.
A Promise represents work that will either fulfill with a value or reject with a reason.
loadData() .then(data => render(data)) .catch(error => showError(error));
Async JavaScript
A promise starts pending. It later becomes fulfilled or rejected. Once settled, it stays settled.
then handles fulfillment. catch handles rejection. finally runs after either outcome.
Promise chains return new promises, which lets you transform values step by step.
Initial state before the result is known.
The operation completed successfully.
The operation failed.
Either fulfilled or rejected.
Examples
function loadTitle() {
return fetchData()
.then(data => data.title);
}
function loadTitle() {
fetchData().then(data => data.title);
}
// The function returns undefined.
Code patterns
These examples are the async patterns you will reuse: timers, promises, composition, await, fetch and cancellation.
Transform a fulfilled value.
getNumber() .then(value => value * 2) .then(result => console.log(result));
Handle rejected promises.
loadData().catch(error => {
console.error(error.message);
});
Runs after success or failure.
loadData().finally(() => {
button.disabled = false;
});
Wrap async completion carefully.
const delay = ms => new Promise(resolve => {
setTimeout(resolve, ms);
});
Rules that matter
Async JavaScript is easier when every operation has clear pending, success, failure and cancellation behavior.
Callers need to wait or catch.
Unhandled rejections are bugs.
Loading state should clear after either outcome.
Return from then instead of nesting deeper.
Many APIs already return promises.
A promise does not change again after fulfillment or rejection.
Production thinking
Promises are the foundation of modern async JavaScript, including fetch and async/await.
Promise-based UI should expose loading and error messages in readable text.
Production promise chains need consistent catch handling and cleanup.
Promise failures during rendering can leave pages incomplete if not handled.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain when the code runs, how it fails and what happens if it becomes irrelevant, you understand the async model.
Senior audit upgrade
A promise is a value representing future completion: pending, fulfilled or rejected.
start async work -> pending promise -> fulfilled value OR rejected reason -> then/catch/finally path