I asked a question about callbacks and arrived at another question (see comment). How is a closure different from a callback?
What is a callback function?
A callback function is a function which is:
in Plain English we say A callback is any function that is called by another function, which takes the first function as a parameter or function passed as an argument
It is also common to say "call upon a function", "start a function", or "execute a function".
function getUserInput(firstName, lastName, age, callback2,callback1) {
var fullName = firstName + " " + lastName;
// Make sure the callback is a function
if (typeof callback2 === "function") {
// Execute the callback function and pass the parameters to it
callback2(fullName, age);
}
if (typeof callback1 === "function") {
callback1(lastName);
}
}
function callbackforlastname1(lname){
console.log("---");
}
function genericPoemMaker(name, aged) {
console.log(name + " is finer than fine wine.");
console.log("A " + aged + " of unfortunl smile");
}
getUserInput("Avinash", "Maurya", "26", genericPoemMaker,callbackforlastname1);