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

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


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>