> For the complete documentation index, see [llms.txt](https://jack1in.gitbook.io/font-end/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack1in.gitbook.io/font-end/2.-javascript/2.1-es6/2.1.6-promise.md).

# 2.1.6 Promise

Promise 有三種狀態

1. pending: 等待中的初始狀態
2. resolved: 正確完成
3. rejected: 已拒絕，操作失敗

```
var isMomHappy = false

var willIGetNewPhone = new Promise(function (resolve, reject) {
  if (isMomHappy) {
    var phone = {
      brand: 'iphone',
      color: 'black',
      type: 'x'
    }
    resolve(phone)
  } else {
    var reason = new Error('Mom is unhappy')
    reject(reason)
  }
})
```

```
var askMom = function () {
  willIGetNewPhone
    .then(function (fulfilled) {
      console.log(fulfilled)
    })
    .catch(function (error) {
      console.log(error.message)
    })
}
askMom()
```
