How to define rest parameter for a function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

With rest parameter, you can represent a number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precedes a parameter.


Let’s see the following code snippet to define rest parameter.

         function addition(…numbers) {
            var res = 0;
            numbers.forEach(function (number) {
               res += number;
            return res;
Published on 25-Jan-2018 11:24:22