Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 29, 2022 07:06 pm GMT

Callback Function

Hi guys,

Today we are going to discuss the Callback function.

Callback is the one of the weird concept if you people are coming from the C programming language.

Callback is nothing but a function which is passed as an parameter to the other function and being used inside that(the function where it is passed as an parameter.) function

Example

function greeting(name) {
alert('Hello ' + name);
}

function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}

processUserInput(greeting);

Example Source

Snippet Explanation :

  • First the proceessUserInput method executes which takes greeting function as an parameter, Where the first line of the method asks as to type the name.

  • Second line where the greeting(callback) function calls which the function inside the other function.

  • It takes name output from the processUserInput and alerts the greeting message.

OUTPUT

Please enter your name. John

Hello John

That's it

Thanks! for reading

Comment your feedback to boost up my writing


Original Link: https://dev.to/jana009/callback-function-3dml

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To