Higher-Order Functions

Austin vollman
2 min readNov 17, 2020

--

Higher-Order functions are one of the most important concepts in coding, and they are one of the reasons it is possible for us to do the amazing things when can do with code. So what is a higher-order function? A higher-order function is a function that takes in a function as an argument or returns a function. Some well-known examples of higher-order functions include filter, map, reduce, and each. So why are higher-order functions so important? One reason is that higher-order functions are a huge time saver. For example, filter is a function that searches through an array and returns all elements that pass as true for a certain condition. As you can see below filter will return an array with all values equal to red. Now, this is a simple example but imagine the helpful possibilities that filter could provide.

Another reason that higher-order functions are so useful is that is simplifies your code. Take the filter function from above for example, below is the implementation of the filter function. All the code inside the filter function implementation has the same thing as the code using the filter function above. However, look at the difference in the lines of code, it is much more simple to use the Higher-Order filter function than to use the code below. This results in cleaner and more efficient code.

Since every developer will become familiar with higher-order functions, another advantage of their use is that other developers will have an easier time making sense of your code. Fucntions like Map, forEach, filter, and reduce are widely used so if another developer is combing through your code, using higher order functions like these will give them a better idea of what you are trying to accomplish.

Higher-Order functions are one of a developers best friends and could save a lot of time and frustration when used properly. So, get familiar with higher-order function soon and use them often.

--

--

Austin vollman
Austin vollman

No responses yet