> For the complete documentation index, see [llms.txt](https://strctr.gitbook.io/programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://strctr.gitbook.io/programming/01-languages/javascript/01-language/e-controls/e4-promises/05-thenables.md).

# 05. Thenable

> “thenable” is an object or function that defines a `then` method that follow Promise specification.

A thenable is an object that has a Promise-style `then()` method. Whenever the API is only interested in being notified of settlements, it only demands thenables (e.g. the values returned from `then()` and `catch()`; or the values handed to `Promise.all()` and `Promise.race()`).

```javascript
// Resolving a thenable object
const p1 = Promise.resolve({
  then(onFulfill, onReject) {
    onFulfill("fulfilled!");
  }
});

console.log(p1 instanceof Promise); // true, object casted to a Promise

p1.then(
  value => {
    console.log(value); // "fulfilled!"
  },
  e => {
    // not called
  }
);
```
