Thursday, May 4, 2017

CallBack Functions

CallBack Function

Once its parent function completes, the function passed as an argument is then called

Simple example of callback function

This is an simple example for a callback function.

Steps involved for creating a callback function

Define the callback function

Define a function which takes the callback function as its input parameter

We need to call the callback function within the function, callback();

Have a function call and send values to the callback function as parameter.

/*FunctioncallbackWecanpassafunctionasanargumenttoanotherfunction**///Thisfunctionispassedasparameterletx=function(){console.log("Called form inside a function.")}lety=function(callback){console.log('Called first.');callback();}//Callingfunctionywithxascallbackfunction.y(x);