How to pass the value 'undefined' to a function with multiple parameters in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To set the 2nd parameter as undefined, just set it to the following −

displayFunc(undefined, "Amit");

Example

Here’s an example displaying the second parameter successfully when the first is set as “undefined”

Live Demo

<!DOCTYPE html>
   <html>
      <body>
         <script>
            function displayFunc (p1, p2) {
               document.write("Parameter 1 = "+p1);
               document.write("<br>Parameter 2 = "+p2);
            }
            displayFunc(undefined, "Amit");
      </script>
   </body>
</html>
raja
Published on 24-Jan-2018 07:13:45
Advertisements