Single Line Block Arrow Function Throws Error with a Semicolon

function getAverageRating(arr) {
let summedValue = arr.reduce((accumulator, currentValue) => currentValue + accumulator;)
let count = arr.length;
return summedValue / count;
}

I am getting an error with this code because I have a semicolon at the end of the arrow function that is being used as the reduce callback function. Once I remove the semicolon the error goes away.
Any explanation as to why the semicolon is not allowed?

We only write semi-colon at the end of a statement, not the end of an expression. A concise body arrow function is an expression.

1 Like