CKTIS / JavaScript
Promise.prototype.then — chaining asynchronous operations
Promise.prototype.then registers fulfillment or rejection handlers and returns a new promise. The handler's result determines how the chain continues.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
promise.then(onFulfilled, onRejected)Promise.prototype.then accepts optional onFulfilled and onRejected handlers. The first receives the fulfillment value; the second receives the rejection reason. The call returns a new promise; handlers run asynchronously, after the current synchronous code finishes, even when the original promise is already settled.
Returning an ordinary value fulfills the new promise, while throwing an exception rejects it. Returning a promise or an object with a callable then method adopts its eventual outcome. Omitting return produces undefined. Return asynchronous operations so the chain waits for them.
Non-callable arguments are treated as missing handlers: the fulfillment value or rejection reason passes through. onRejected does not catch an exception thrown by onFulfilled in the same then call; handle it in a later link. Returning normally from onRejected can recover to fulfillment.
This is an ECMAScript mechanism, not a Web API. The method requires an actual promise as this; merely having a then method is insufficient. The example demonstrates deferred handling, value transformation, and error recovery.
Examples
console.log('start');
Promise.resolve(3)
.then(value => value * 2)
.then(value => {
console.log(value);
throw new Error('boom');
})
.then(undefined, error => {
console.log(error.message);
return 9;
})
.then(value => console.log(value));
console.log('end');Result
start end 6 boom 9
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.