Skip to content

Commit

Permalink
Translation zh-TW answer 81
Browse files Browse the repository at this point in the history
  • Loading branch information
sexyoung committed Jul 2, 2021
1 parent 0aa2e63 commit fd8b384
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions zh-TW/README_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2551,4 +2551,36 @@ console.log(list)
</p>
</details>

---
###### 81. 將會輸出什麽內容?

```javascript
function sayHi(name) {
return `Hi there, ${name}`
}

console.log(sayHi())
```

- A: `Hi there, `
- B: `Hi there, undefined`
- C: `Hi there, null`
- D: `ReferenceError`

<details><summary><b>答案</b></summary>
<p>

#### 答案: B

預設情況下,如果不傳參數給函數,函數內參數的值將為`undefined`。上述情況,我們沒有給參數`name`傳值。 `name`等於`undefined`,並被印出。

在ES6中,我們可以使用預設參數覆蓋此預設的`undefined`值。例如:

`function sayHi(name =“Lydia”){...}`

在這種情況下,如果我們沒有傳遞值或者如果我們傳遞`undefined``name`總是等於字符`Lydia`

</p>
</details>

---

0 comments on commit fd8b384

Please sign in to comment.