File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -3375,4 +3375,43 @@ compareMembers(person)
3375
3375
</p >
3376
3376
</details >
3377
3377
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
+ ---
You can’t perform that action at this time.
0 commit comments