DEV Community

Discussion on: Arrow functions: a walkthrough and gotchas

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

and you need {} as soon as you have more than 1 line of function body

Almost but not completely correct. You need {} when the function body is not just one expression, that is, when you need additional statements before the return value. You can easily write something like

const sum = (array) => array
   .reduce( (a,b) => a+b);

but you can't do

const sumPlusOne = (a, b) => a+=1; a+b
Collapse
 
sylwiavargas profile image
Sylwia Vargas • Edited

Good catch! I've edited the post to include your comment and attributed it to you :)