Computer >> Computer tutorials >  >> Programming >> Javascript

What are Rest parameters in JavaScript functions?


ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and precede a parameter.

Example

Let’s see the following code snippet −

<html>
   <body>
      <script>
         function addition(…numbers) {
            var res = 0;
            numbers.forEach(function (number) {
               res += number;
            });
            return res;
         }
         document.write(addition(3));
         document.write(addition(5,6,7,8,9));
      </script>
   </body>
</html>