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);
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
Top comments (0)