What are default function parameters in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The default parameters came to handle function parameters with ease. You can easily set default parameters to allow initializing formal parameters with default values. This is possible only if no value or undefined is passed.

Example

Let’s see an example −

<html>
   <body>
      <script>
         // default is set to 1
         function inc(val1, inc = 1) {
            return val1 + inc;
         }

         document.write(inc(10,10));
         document.write("<br>");
         document.write(inc(10));

      </script>
   </body>
</html>
raja
Published on 16-Feb-2018 16:27:58
Advertisements