Open this example in the interactive library
Source code
const sum = (...values) => values.reduce((a, b) => a + b, 0);
console.log(sum(2, 3, 4));
Sample output
9

Use rest parameters. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const sum = (...values) => values.reduce((a, b) => a + b, 0);
console.log(sum(2, 3, 4));
9