Articles → JAVASCRIPT → Rest parameters in JavaScript

Rest parameters in JavaScript






Purpose







Example




<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8" />
      <title></title>
      <script type="module" src="ImportClass.js"></script>
      <script>
         function sum(...args) {
             document.write("Calling sum function with " + args.length + " parameters");
             document.write("<br/>");
         }
         
         sum(1, 2);
         sum(1, 2, 3);
         sum(1, 2, 3, 4);
      </script>
   </head>
   <body>
   </body>
</html>





Output


Picture showing the output of rest parameters in JavaScript

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, August 24, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250