Curly braces in arrow functions

Can someone please explain the following:

I follow Dan Abramov’s lectures and do exercises.

The code works fine, but tests fail when the next specific function is written in curly brackets **{ }** .

  case 'toggleTodo' : return ( state.map( (one) => { oneTodo( one, action ) }) ); 

The same code works fine without curly braces.

  case 'toggleTodo' : return ( state.map( (one) => oneTodo( one, action ) ) ); 

Here is the JsBin . Please refer to line 31 onwards.

+14
javascript ecmascript-6 curly-braces arrow-functions brackets
source share
2 answers
 case 'toggleTodo' : return ( state.map( (one) => oneTodo( one, action ) ) ); 

equally:

 case 'toggleTodo' : return ( state.map( (one) => { return oneTodo( one, action ) }) ); 

see return statement

+12
source share

A pair of braces forms a block containing a list of operators. You must explicitly use the return in order for the function to return something.

If you omit curly braces, the arrow function has a short body consisting solely of one expression, the result of which will implicitly become the return value of the function.

+16
source share

All Articles