How to invoke a JavaScript Function with 'new' Function Constructor?

JavascriptWeb DevelopmentFront End Technology

The Function() constructor expects any number of string arguments. The last argument is the body of the function - it can contain arbitrary JavaScript statements, separated from each other by semicolons.


You can try to run the following code to invoke a function with new Function Constructor −

         var func = new Function("x", "y", "return x*y;");
         function multiplyFunction() {
            var result;
            result = func(15,35);
            document.write ( result );
      <p>Click the following button to call the function</p>
         <input type="button" onclick = "multiplyFunction()" value="Call Function">
Updated on 19-Jun-2020 11:28:38