Promise.prototype.then
Attaches callbacks for the resolution and/or rejection of the Promise, and returns a new Promise
Syntax
promise.then(onFulfilled?, onRejected?)Parameters
| Parameter | Type | Description |
|---|---|---|
| onFulfilled | (value: T) => T2 | PromiseLike<T2> | Callback for when the promise is fulfilled |
| onRejected | (reason: any) => T2 | PromiseLike<T2> | Callback for when the promise is rejected |
Return Value
A new Promise based on the value returned by the handler
Examples
fetch('/api/data')
.then(response => response.json())
.then(data => console.log(data));Promise.resolve(1)
.then(v => v + 1)
.then(v => v * 2)
.then(v => console.log(v)); // 4const result = await Promise.resolve('hello')
.then(s => s.toUpperCase())
.then(s => s + '!');
console.log(result); // 'HELLO!'Understanding Promise.prototype.then
The Promise.prototype.then method in JavaScript attaches callbacks for the resolution and/or rejection of the Promise, and returns a new Promise. It belongs to the Promise object and is one of the most widely used methods for working with promise values in modern JavaScript and TypeScript applications.
The method signature is promise.then(onFulfilled?, onRejected?). It accepts 2 parameters: onFulfilled, onRejected. When called, it returns a new promise based on the value returned by the handler. Understanding when and how to use then() helps you write more expressive, readable code.
Common use cases for Promise.prototype.then include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-catch, promise-finally, promise-resolve, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Promise.prototype.then is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Promise.prototype.catchAttaches a rejection handler callback to the promise and returns a new Promise resolving to the return value of the callback if called, or the original fulfilled value if the promise is resolved
Promise.prototype.finallyAttaches a callback that is invoked when the promise is settled (either fulfilled or rejected), and returns a new Promise
Promise.resolveReturns a Promise object that is resolved with a given value
More Promise Methods
Other methods in the Promise object
Related Tools
More Promise Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.