Skip to content

Instantly share code, notes, and snippets.

@bhaveshdaswani93
Created December 28, 2019 03:11
Show Gist options
  • Save bhaveshdaswani93/0308163d540c605ea92102f696157d78 to your computer and use it in GitHub Desktop.
Save bhaveshdaswani93/0308163d540c605ea92102f696157d78 to your computer and use it in GitHub Desktop.
In this example i will explain high order function
const hocFn = function() {
return function() {
return 5;
}
}
hocFn() // will return function
hocFn()() // will return 5
// hocFn return function so it is HOC
const fn = function(x) {
return x*2;
}
const hocFn2 = function(fn) {
return fn(5);
}
hocFn2(fn); // will return 10
// hocFn2 accept function as argument it is an HOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment