A concise body arrow function allows you to write short, single-expression functions in a more compact form. The function implicitly returns the result of the expression without the need for a return
statement or curly braces {}
.
The comma operator evaluates multiple expressions from left to right and returns the value of the last expression. This operator can be used within an arrow function to perform multiple operations in a single line.
Syntax
param => (expression1, expression2);
Examples
const double = number => (console.log(number), number * 2);
const sum = (a, b) => (console.log(a), console.log(b), a + b);
Equivalents
// arrow function
const double = number => {
console.log(number);
return number * 2;
};
// traditional function declaration
function double(number) {
console.log(number);
return number * 2;
}