promise.then(onFulfilled, onRejected) tells a promise what to do next. When the promise fulfills, your function receives its value. The key point: then() always returns a new promise. What your function returns becomes the value of that new promise, and a thrown error makes it reject. That is how steps are chained.
Remember
const next = promise.then(onFulfilled, onRejected);
next is a NEW promise, never the same object
fn returns 5 → next fulfills with 5
fn returns a promise → next waits and copies it
fn throws an error → next rejects with that error
Syntax
Call then on any promise. Pass one function for success, and optionally a second one for failure.
Every then() makes a new promise.start.then(...) leaves start alone and gives back doubled. They are two different objects, so the comparison prints false.
The callback waits its turn. JavaScript finishes the whole script first, so This line runs first appears before Result: 10, although the then call is higher up.
Return values travel down the chain. The first callback turns 5 into 10. That 10 is the value of doubled, and the next callback joins it into Result: 10.
Example 2 — Why return Matters Inside then()
Load a name, then its orders. Run the chain twice: with a forgotten return, then with the fix.
Without return: undefined
With return: ["Asha order 1","Asha order 2"]
How It Works
A function without return gives undefined. The first callback calls loadOrders(name) but throws the promise away. It ends with nothing, so the next step gets undefined at once.
Returning a promise makes then() wait. With return loadOrders(name), then() follows that promise. The chain pauses about 30 ms and continues with the real orders.
Always return what the next step needs. Write return for any value or promise you want later. Short arrow functions such as (name) => loadOrders(name) return on their own.
Example 3 — The Second Argument and Thrown Errors
The failure function belongs to the promise it is attached to. See what it can and cannot catch.
rejected: server is down
found later: bug inside the success handler
How It Works
Two functions, one of them runs.failed is already rejected, so then() skips the success function and calls the second one, printing rejected: server is down.
Neighbors do not protect each other. In twoArgs the success function throws. The failure function next to it only watches the original promise, so never printed stays unprinted.
The next link receives the error. The throw makes twoArgs a rejected promise, and the last then() handles it. A .catch() there does the same with less typing.
Compatibility
Browser & Runtime Support
Promise.prototype.then() is part of ES2015 (ES6), together with the Promise constructor.
✓ Baseline · ES2015
Promise.prototype.then()
Supported in every modern browser, plus Node.js, Deno, and Bun. Internet Explorer has no native Promise.
BaselineEvery modern browser
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
Node.jsAll current releases
Supported
DenoAll releases
Supported
Internet ExplorerNo native support
Not supported
then()Excellent
Bottom line: Safe everywhere today. Only very old browsers such as Internet Explorer need a polyfill.
Frequently Asked Questions
A new promise. It fulfills with what your callback returns, follows a returned promise, and rejects if your callback throws. The original promise is never changed.
Promise callbacks are queued and run only after the current synchronous code has finished. So lines after promise.then(...) always run first.
With then(a, b), function b only handles a rejection of the original promise. If a throws, b does not see it. With then(a).catch(b), the catch also handles errors thrown inside a.
The previous callback did not return anything, and a function without a return statement gives undefined. Add return before the value or promise the next step needs.
They use the same promise machinery. await pauses an async function and gives you the value, as if the rest of the function were inside promise.then(...).