In this question we will briefly understand what is first order, higher order, and callback functions.
Let’s consider below code.
function Message(msg){
console.log('Message is:'+msg);
}
function Print(message){
message("testing message");
}
Print(Message);
Note here that function Print is taking the function Message as a input function having expectation that internally Print function will call the Message function. in javascript such functions are commonly called as callback functions.
Here, Print function is taking another function as it’s argument hence Print function is called higher order function.
Callback function has extensive usage in javascript. It permits the caller function to invoke the callback function whenever it is needed.
- First class/ Order / Anonymous function :
var a = function () {
console.log("First order or Anonymous function")
}
a()
a is variable here and it holds a function. Here, a is called as first order/class functions.