Passing a function as a callback in JavaScript

Prabhukiran345
Posted by Prabhukiran345 under JavaScript category on | Points: 40 | Views : 437
Callback functions play an important role in many frameworks, including JQuery. Calling a Function as CallBack is an interesting topic in Javascript. It can be Done as:

function action (callback, x, y) {
var result = callback(x, y);
alert(result);
}

function add(x, y) {
return x + y;
}

function multiply(x, y) {
return x * y;
}

action(add, 2, 3); // => 5
action(multiply, 2, 3); // => 6

Comments or Responses

Login to post response