> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/async/promise.md).

# Promise

[JS](/web/js.md) ⟩ [async](/web/js/async.md) ⟩ Promise

{% hint style="success" %}
[⭐️ ES6 (2015)](/web/js/feature/es6.md) \
the <mark style="color:red;">**future**</mark>**&#x20;**<mark style="color:yellow;">**result**</mark> of an [**async**](/web/js/async.md) operation.

```javascript
let p = promise.then(onFulfilled, onRejected)
```

{% endhint %}

{% tabs %}
{% tab title="🔸 定義" %} <img src="/files/xt4RyXvx1IOi3wdCGXmk" alt="" class="gitbook-drawing">

{% hint style="success" %}
if we have：

```javascript
let p = promise.then(onResolved, onRejected)
```

we say p is：

* <mark style="color:purple;">**resolved**</mark> if **onResolved()** is called.
  * <mark style="color:green;">**fulfilled**</mark> if **onResolved()** returns a **non-Promise** value.
* <mark style="color:red;">**rejected**</mark> if <mark style="color:red;">`onRejected()`</mark> is called.
* <mark style="color:orange;">**settled**</mark> if it's <mark style="color:green;">**fulfilled**</mark> **or** <mark style="color:red;">**rejected**</mark>.
* <mark style="color:yellow;">**pending**</mark> if it's **neither** <mark style="color:green;">**fulfilled**</mark> **nor** <mark style="color:red;">**rejected**</mark>.
  {% endhint %}

{% hint style="warning" %}
Any <mark style="color:orange;">**settled**</mark> Promise has an associated <mark style="color:yellow;">**value**</mark> , which <mark style="color:red;">**won't change**</mark>.
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* [using Promises](/web/js/async/promise/using-promises.md)
  * [getJSON()](/web/js/async/promise/custom-promises/getjson.md) - get JSON ([Promise](/web/js/async/promise.md)) from [URL](/web/browser/api/url.md).
* [error handling](/web/js/async/promise/error-handling.md)
  * [recoverable errors](/web/js/async/promise/error-handling/recoverable-errors.md)
  * [finally()](/web/js/async/promise/error-handling/finally.md)
* [chaining Promises](/web/js/async/promise/chaining.md)
* [Promises in parallel](/web/js/async/promise/in-parallel.md)
  {% endtab %}

{% tab title="👥 相關" %}

* [⭐️ ES2018](/web/js/feature/es2018.md) - [for-await](/web/js/grammar/statement/loop/for/await.md), [finally()](/web/js/async/promise/error-handling/finally.md)
* [await](/web/js/async/await.md)
* [await promises](/web/js/async/await/promises.md)
* [Promise.wait()](/web/js/async/promise/custom-promises/promise.wait.md)
* [Promise.inSeries()](/web/js/async/promise/chaining/promise.inseries.md)
* [Promises in parallel](/web/js/async/promise/in-parallel.md)
* [async function](/web/js/async/async/functions.md)
* [async method](/web/js/async/async/methods.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] JavaScript: The Definitive Guide (13.2 Promises)
* [ ] amazon.jp ⟩ [マンガでわかる JavaScript の Promise](https://www.amazon.co.jp/dp/B09XQ89M9Y/ref=olp-opf-redir?aod=1) ([Kindle Cloud Reader](https://read.amazon.co.jp/manga/B09XQ89M9Y?ref_=dbs_t_r_mwr))
  {% endtab %}

{% tab title="📘 手冊" %}

* [Promise.resolve()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
* [Promise.reject()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/async/promise.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
