DEV Community


Posted on

Callback function() in JavaScript

A callback is A reference to executable code, or a piece of executable code, that is passed as an argument to other code or function that is to be executed after another function has finished executing.

In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code that is expected to call back (execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback. Programming languages support callbacks in different ways, often implementing them with subroutines, lambda expressions, blocks, or function pointers.

Let take an example of Callback function() examples.

function addition(a,b) { console.log("Addition of a+b=", a + b); } function numberAddtion(callback) { a = 10; b=20; callback(a,b); } numberAddtion(addition); //output 30

Top comments (0)