Skip to content

Commit 8b8c411

Browse files
committed
Translation zh-TW answer 106
1 parent a55f4ad commit 8b8c411

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

zh-TW/README_zh-TW.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3375,4 +3375,43 @@ compareMembers(person)
33753375
</p>
33763376
</details>
33773377

3378-
---
3378+
---
3379+
###### 106. 將會輸出什麽內容?
3380+
3381+
3382+
```javascript
3383+
const colorConfig = {
3384+
red: true,
3385+
blue: false,
3386+
green: true,
3387+
black: true,
3388+
yellow: false,
3389+
}
3390+
3391+
const colors = ["pink", "red", "blue"]
3392+
3393+
console.log(colorConfig.colors[1])
3394+
```
3395+
3396+
- A: `true`
3397+
- B: `false`
3398+
- C: `undefined`
3399+
- D: `TypeError`
3400+
3401+
<details><summary><b>答案</b></summary>
3402+
<p>
3403+
3404+
#### 答案: D
3405+
3406+
在JavaScript中,我們有兩種存取物件屬性的方法:括號表示法或點表示法。在此範例中,我們使用點表示法(`colorConfig.colors`)代替括號表示法(`colorConfig [“ colors”]`)。
3407+
3408+
使用點表示法,JavaScript會嘗試使用該確切名稱在物件上查找屬性。在此範例中,JavaScript嘗試在colorconfig物件上找到名為colors的屬性。沒有名為“colors”的屬性,因此得到“undefined”。
3409+
然後,我們嘗試使用`[1]`存取第一個元素的值。我們無法對未定義的值執行此操作,因此會拋出`Cannot read property '1' of undefined`
3410+
3411+
JavaScript解釋(或取消裝箱)語句。當我們使用中括號表示法時,它會看到第一個左方括號`[`並一直進行下去,直到找到右方括號`]`。只有這樣,它才會評估該語句。如果我們使用了colorConfig [colors [1]],它將得到colorConfig物件上red屬性的值。
3412+
3413+
3414+
</p>
3415+
</details>
3416+
3417+
---

0 commit comments

Comments
 (0)