Here, we've tightened our original implementation by isolating the injection of the function from the application of summing a range by returning the function that applies the summing over a range. In doing so, we've also managed to strip an extra line of code from the original implementation.IMHO usage of the function has improved also. I now have more options to be expressive:

Closing

They should be considered when you find yourself calling the same function and passing mostly the same parameters. The programming technique of writing functions that take one or more functions and return a function is also known as currying.Javascript implementations provide a host of higher order functions: Array.forEach, map, fold or reduce, filter, compose, partial, and others.