Understanding arrow functions (using curly brackets)

I’m currently doing the JavaScript “Learn localStorage by Building a Todo App” project (step 9 although not relevant to my question). I was looking at the code already written and saw the below:

On the top and bottom arrow function, no curly brackets are used, but the middle does use curly brackets. What difference does this make? I thought you didn’t need to use {} when there was only a single expression?

without curly brackets it means implicit return, the expression to the right of the arrow is returned

with curly brackets, you need to use return to establish what is returned from the function

in this case it doesn’t make any difference, it’s important to know in two cases:
if your function has a multiline body, the curly brackets are mandatory
if your function’s output is important, you need to know how to establish the returned value

1 Like