How do we use function literal to define a function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

JavaScript 1.2 introduces the concept of function literals, which is another new way of defining functions. A function literal is an expression that defines an unnamed function.


You can try the following example to implement functional literals in JavaScript

Live Demo

            var func = function(x,y){ return x*y };
            function secondFunction(){
               var result;
               result = func(10,20);
               document.write ( result );

      <p>Click the following button to call the function</p>
         <input type="button" onclick="secondFunction()" value="Call Function">
      <p>Use different parameters inside the function and then try...</p>
Published on 07-Feb-2018 11:50:12