Promise

Promise.prototype.then

Attaches callbacks for the resolution and/or rejection of the Promise, and returns a new Promise

Syntax

JavaScript
promise.then(onFulfilled?, onRejected?)

Parameters

ParameterTypeDescription
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

Basic Usage
fetch('/api/data')
  .then(response => response.json())
  .then(data => console.log(data));
Practical Example
Promise.resolve(1)
  .then(v => v + 1)
  .then(v => v * 2)
  .then(v => console.log(v)); // 4
Advanced Usage
const 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

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.