marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
2.99k stars 790 forks source link

array parameter require parentheses #545

Closed gumbol closed 3 years ago

gumbol commented 3 years ago

following the ch3 arrow functions definition explanation.

this function definition throws a malformed arrow function error. arr = [ele] => ele >1;

this however works arr = ([ele]) => ele > 1;

it seems that arrays are not treated as a single parameter.

marijnh commented 3 years ago

Only plain parameters allow you to omit the parentheses for a single parameter. When destructuring or adding a default value, you always have to include them.

gumbol commented 3 years ago

awesome thanks!