Higher order functions are functions which take other function as a parameter or return a function as a value. The function passed as a parameter is called callback.
A callback is a function which can be passed as parameter to other function.
|
|
Higher order function return a function as a value.
|
|
In the above example welcome
function is the higher order function, which returns salutation
function and which inturn returns name
function. finally we call temp3
function which returns Hello Mr. John
.
Currying is a technique to convert a function with multiple arguments into a sequence of functions each with a single argument. In the previous snippet we’ve used temp
variables. But this will be a tedious process to get the result when the function is of n
length.
The same can be called by using currying technique as welcome("Hello")("Mr.")("John")
to get the same output.