Skip to content

Commit 64a813c

Browse files
committed
Translation zh-TW answer 74
1 parent 7900c43 commit 64a813c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

zh-TW/README_zh-TW.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,3 +2315,33 @@ console.log(data);
23152315
</details>
23162316

23172317
---
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

Comments
 (0)