Skip to content

Commit 7900c43

Browse files
committed
Translation zh-TW answer 73
1 parent 5c3e9ac commit 7900c43

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

zh-TW/README_zh-TW.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,4 +2280,38 @@ console.log(String.raw`Hello\nworld`);
22802280
</p>
22812281
</details>
22822282

2283-
---
2283+
---
2284+
2285+
###### 73. 將會輸出什麽內容?
2286+
2287+
```javascript
2288+
async function getData() {
2289+
return await Promise.resolve('I made it!');
2290+
}
2291+
2292+
const data = getData();
2293+
console.log(data);
2294+
```
2295+
2296+
- A: `"I made it!"`
2297+
- B: `Promise {<resolved>: "I made it!"}`
2298+
- C: `Promise {<pending>}`
2299+
- D: `undefined`
2300+
2301+
<details><summary><b>答案</b></summary>
2302+
<p>
2303+
2304+
#### 答案: C
2305+
2306+
一個異步函數總是返回一個 promise 。 `await` 仍然要等待 promise 的 resolve:當我們呼叫 `getData()` 等於 `data` 時,會得到一個等待的 promise。
2307+
2308+
如果我們想獲取 resolve 後的值`"I made it"`,我們可以在`data`上使用`.then()`函數:
2309+
2310+
`data.then(res => console.log(res))`
2311+
2312+
這樣就會出現 `"I made it!"` 的記錄。
2313+
2314+
</p>
2315+
</details>
2316+
2317+
---

0 commit comments

Comments
 (0)