Pass function as a parameter - Javascript Function

Javascript examples for Function:Function Variable

Description

Pass function as a parameter

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <script>
function myFunction(callback) {/*from  ww  w  .j  av a2 s  . c  om*/
  console.log("I'm about to run the callback");
  callback();
}
myFunction(function() {
  console.log("Inside the callback");
});

      </script>  
   </body>
</html>

Related Tutorials