We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7900c43 commit 64a813cCopy full SHA for 64a813c
zh-TW/README_zh-TW.md
@@ -2315,3 +2315,33 @@ console.log(data);
2315
</details>
2316
2317
---
2318
+
2319
+###### 74. 將會輸出什麽內容?
2320
2321
+```javascript
2322
+function addToList(item, list) {
2323
+ return list.push(item);
2324
+}
2325
2326
+const result = addToList('apple', ['banana']);
2327
+console.log(result);
2328
+```
2329
2330
+- A: `['apple', 'banana']`
2331
+- B: `2`
2332
+- C: `true`
2333
+- D: `undefined`
2334
2335
+<details><summary><b>答案</b></summary>
2336
+<p>
2337
2338
+#### 答案: B
2339
2340
+`.push()`函數回傳的是陣列的長度!原本陣列包含一個元素(字串`"香蕉"`),長度為`1`。後來將字串 `"apple"` 加到陣列中後,陣列包含兩個元素。所以會從`addToList`函數中得到,長度為 `"2"`。
2341
2342
+`push`函數修改了原來的陣列。如果你想從函數中返回 _陣列_ 而不是 _陳列的長度_ ,你應該在加完`item`到陣列後,回傳`list`。
2343
2344
+</p>
2345
+</details>
2346
2347
+---
0 commit comments