Promise states, settlement and resolution
How it works
A promise is initially pending and can become fulfilled with a value or rejected with a reason. Fulfilled and rejected are settled states. Resolved is broader: a promise resolved to another pending promise is locked into following that promise but may still be pending. The executor runs synchronously when constructed; subsequent calls to its resolving functions cannot change the selected outcome. Handlers run asynchronously.
Example 1
const p = new Promise(resolve => { console.log("executor"); resolve(4); });p.then(n => console.log(n));console.log("after");Expected output in the tested environment:
executorafter4Construction is synchronous; the reaction is deferred.
Example 2
const p = new Promise((resolve, reject) => { resolve(2); reject("late"); resolve(9); });p.then(console.log);Expected output in the tested environment:
2Only the first resolving action selects the outcome.
Common mistake
Resolved does not always mean fulfilled. A promise following a pending promise has not yet settled.
Practice
Create an inner promise with an exposed resolver and an outer promise that resolves to it; resolve the inner only after printing a synchronous marker.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Promise states, settlement and resolution — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
Which two states count as settled?
Can a resolved promise still be pending?
When does the new Promise executor begin?
For Promise states, settlement and resolution, what is the console output of example 1 in Node.js 22.16.0?
const p = new Promise(resolve => { console.log("executor"); resolve(4); });p.then(n => console.log(n));console.log("after");For Promise states, settlement and resolution, what is the console output of example 2 in Node.js 22.16.0?
const p = new Promise((resolve, reject) => { resolve(2); reject("late"); resolve(9); });p.then(console.log);