JavaScript code showing use of spread and gather operators to sum an array using a function with rest parameters and reduce method.

This image displays a JavaScript code example that explains the use of spread and gather (rest) operators. The addNumbers function uses the gather operator (…numbers) to collect multiple arguments into an array. The reduce method is used to calculate the sum. The numArr array is passed into the function using the spread operator (…numArr), which expands the array into individual arguments. Annotations in the image identify the spread and gather operators, and the output is logged as 15.

×

Table Of Content