File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -2280,4 +2280,38 @@ console.log(String.raw`Hello\nworld`);
2280
2280
</p >
2281
2281
</details >
2282
2282
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
+ ---
You can’t perform that action at this time.
0 commit comments