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");


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

Live Demo

<!DOCTYPE html>
            function displayFunc (p1, p2) {
               document.write("Parameter 1 = "+p1);
               document.write("<br>Parameter 2 = "+p2);
            displayFunc(undefined, "Amit");
Updated on 12-Jun-2020 08:05:42