DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

CallBack Functions in JavaScript

Callback Functions:let me explain to you in simple words .We call the second function through first function which takes second function as argument in 1st .

function printFirstName(firstname,cb)
{
console.log(firstname);
cb("Verma");
}

function printLastName(lastname)
{
console.log(lastname);
}

printFirstName("pushan",printLastName);

Top comments (6)

Collapse
 
peerreynders profile image
peerreynders •

There is nothing simple about callbacks.

JavaScript code is fundamentally synchronous. Callback functions can be synchronous depending on the circumstances but they often are a means towards asynchronous processing.

To understand that you have to understand the event loop.

Collapse
 
pushanverma profile image
PUSHAN VERMA •

Sometimes people just want to know that is the gist of the topic , in a very few lines. I try to provide that . Someone with little knowledge of JS can also get a idea. Full articles are available at medium etc. but I want to provide short and crisp explanation.

Thanks
Pushan

Collapse
 
bgw8 profile image
Emil Rydén •

?

Collapse
 
pushanverma profile image
PUSHAN VERMA •

let me explain to you in simple words .We call the second function through first function which takes second function as argument in 1st .

Collapse
 
bgw8 profile image
Emil Rydén •

I understand call backs. What I dont understand is why you’re making a post with no information, context or description what so ever except for a simple code excerpt.

Thread Thread
 
pushanverma profile image
PUSHAN VERMA •

Sometimes people just want to know that is the gist of the topic , in a very few lines. I try to provide that . Someone with little knowledge of JS can also get a idea. Full articles are available at medium etc. but I want to provide short and crisp explanation.

Thanks
Pushan