Callback works only if the curly braces on the callback function within the filter method are removed

the following code works if i remove the curly braces on the callback function within the filter method. Can someone please explain why this is so or direct to learning resource?

 filteredList = watchList.map((i)=>{
          return {title: i["Title"],rating: i["imdbRating"]}
          }).filter((i) => {i.rating >= 8});

does not work , but

    filteredList = watchList.map((i)=>{
          return {title: i["Title"],rating: i["imdbRating"]}
          }).filter((i) => i.rating >= 8);

does with curly braces around {i.rating>=8} removed.

I’m looking to understand the concept. Thanks.

When you omit the braces in a one-line arrow function, the expression is implicitly returned.

In the braced version, the expression just sits there, but the function itself returns nothing.

The braced equivalent of the second code is

.filter((i) => { return i.rating >= 8; })
1 Like

Thanks so much. Perfectly clear now. I looked up implicit returns also. will leave the question here in case someone else has it too.