Skip to content

Commit 684a18b

Browse files
authored
Merge pull request lydiahallie#528 from piotrwawrzyn/patch2
Fixes to question 98
2 parents f392bfb + e708073 commit 684a18b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ console.log(getList(list))
31233123
console.log(getUser(user))
31243124
```
31253125

3126-
- A: `[1, [2, 3, 4]]` and `undefined`
3126+
- A: `[1, [2, 3, 4]]` and `SyntaxError`
31273127
- B: `[1, [2, 3, 4]]` and `{ name: "Lydia", age: 21 }`
31283128
- C: `[1, 2, 3, 4]` and `{ name: "Lydia", age: 21 }`
31293129
- D: `Error` and `{ name: "Lydia", age: 21 }`
@@ -3139,11 +3139,11 @@ The `getList` function receives an array as its argument. Between the parenthese
31393139

31403140
With the rest parameter `...y`, we put all "remaining" arguments in an array. The remaining arguments are `2`, `3` and `4` in this case. The value of `y` is an array, containing all the rest parameters. The value of `x` is equal to `1` in this case, so when we log `[x, y]`, `[1, [2, 3, 4]]` gets logged.
31413141

3142-
The `getUser` function receives an object. With arrow functions, we don't _have_ to write curly brackets if we just return one value. However, if you want to return an _object_ from an arrow function, you have to write it between parentheses, otherwise no value gets returned! The following function would have returned an object:
3142+
The `getUser` function receives an object. With arrow functions, we don't _have_ to write curly brackets if we just return one value. However, if you want to instantly return an _object_ from an arrow function, you have to write it between parentheses, otherwise everything between the two braces will be interpreted as a block statement. In this case the code between the braces is not a valid JavaScript code, so a `SyntaxError` gets thrown.
31433143

3144-
`const getUser = user => ({ name: user.name, age: user.age })`
3144+
The following function would have returned an object:
31453145

3146-
Since no value gets returned in this case, the function returns `undefined`.
3146+
`const getUser = user => ({ name: user.name, age: user.age })`
31473147

31483148
</p>
31493149
</details>

0 commit comments

Comments
 (0)