I am trying to understand callback function concept.
Please explain what is the difference between two snippets of code
//callback function
function greeting(name) {
console.log('Hello ' + name);
}
function processUserInput(callback) {
var name = "Johny1";
callback(name);
}
processUserInput(greeting);
and 2nd one
function greeting(name) {
console.log('Hello ' + name);
}
function processUserInput() {
var name = "Johny2";
greeting(name);
}
processUserInput();
why someone uses the callback function when the same thing can be achieved by simple function?