DEV Community

Cover image for Higher-Order Functions(HoF) in JavaScript - Explain Like I'm Five

Higher-Order Functions(HoF) in JavaScript - Explain Like I'm Five

Tapas Adhikary on December 28, 2021

JavaScript Functions Functions are an integral part of many programming languages, and JavaScript is not an exception. In JavaScript, fu...
Collapse
 
lokmanhossainpappu profile image
LokmanHossainPappu

great

Collapse
 
atapas profile image
Tapas Adhikary

Thank you!

Collapse
 
eljayadobe profile image
Eljay-Adobe

Excellent! And you avoided mentioning monad and scaring away the fainthearted.

Collapse
 
suhakim profile image
sadiul hakim

Good job

Collapse
 
atapas profile image
Tapas Adhikary

Thanks a lot 😀

Collapse
 
tleperou profile image
Thomas Lepérou

I still struggle with HoF posts which don't mention closure. I either misunderstand closure concept or HoF purpose. Any guidance?

Collapse
 
atapas profile image
Tapas Adhikary

Hey Thomas, thanks for reading. I kept out closure intentionally in this post. Closure and HoF are integral to each other but when I started explaining it I wanted to focus on the simlicity of understanding HoF with simple examples. The next in the line is to go closure and currying to complete the triology 😀.

Collapse
 
bogdanbatsenko profile image
bogdanbatsenko

Well done. However, I would like to know more about the difference between callback and HOF

Collapse
 
atapas profile image
Tapas Adhikary

Thank you! I have done a detailed explanation of the callback here: freecodecamp.org/news/javascript-c...

Collapse
 
ijash profile image
Jastria Rahmat

So, is HOF is the same concept as Decorator as in python?

And if it's OOP, can this be called some kind of inheritance?

Collapse
 
atapas profile image
Tapas Adhikary

I'm not aware much on Python so can not confirm about it but coming to the OOPs part, it is not exactly inheritance. Inheritance is where we get pass the parent traits to child and also enhance them.

HoF is more to do with function compositions. You create function compose to another, the the output can be composed to another one, and so on.

Collapse
 
tleperou profile image
Thomas Lepérou

JS has landed not that long ago decorators for OOP (mostly) like Python does.