Promises
A promise represents an eventual outcome: pending, fulfilled with a value, or rejected with a reason. then returns a new promise based on its handler’s result.
Return the next result from a handler so the chain can follow it.
See the mechanism
promise has no final outcome yetFollow one example
The first then extracts a title and returns it. The next receives that returned value. A thrown error rejects the next promise, and catch can handle a rejection. Promise.resolve does not move synchronous heavy work to a background thread; the executor of new Promise runs synchronously too. Settled outcomes do not change to another state.
Predict, change and check
Predict: If the first handler uses braces but forgets return, what does the second handler receive?
Test your explanation: Make that mistake and observe undefined, then repair it. Throw an Error in the first handler and follow the rejection to catch.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
The next promise follows the handler result
then returns a new promise. Returning a value fulfills the next step with that value; throwing rejects it; returning another promise makes the chain follow its eventual outcome. Forgetting return inside a block handler often passes undefined to the next step.
The executor passed to new Promise runs synchronously. Creating a promise does not itself move a heavy loop onto another thread. Attach rejection handling intentionally, and return a chain so callers can await its actual completion. A settled promise does not later switch from fulfilled to rejected.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.