DEV Community

averagealloy
averagealloy

Posted on

Jimmy HOFfa

Higher-order functions are an important part of javaScript just like jimmy Hoffa was to the IBT. The blog will talk a bit about some of the confusion points so no one ends up lost, missing, or even worst "disappeared"! If none of this is making any sense it's ok. I will link the wiki down below! But enough of that let's get into some of the confusion.

The Spin Zone

In the beginning, I got higher-order functions and closures mixed up. Higher-order functions are functions that operate on other functions where closures deal with variable scope manipulation.
Now that we are on the topic of confusion we should talk about first-class functions as well. A first-class function is a property of a programing language.
When using a language that supports first-class functions they treat functions as values. This allows a function to take a
function or more than one function as an argument or arguments. I know what you just read seemed like the movie inception. Something inside of something else, it's nuts.
Hopefully, some of these technical examples help you understand this insanity a bit better!

Here is an example of a basic function!

function prod(a, b) {
  return a * b;
}

prod(9,9);

This function is taking both arguments and then multiplying them!

var prod = function(a, b) {
  return a * b;
}

var muffins = prod;

muffins(10,10);

This is interesting muffins now is prod. We can now pass all of the information to this new variable. This would significantly change how our(metaphorical) project would function. (pardon the function pun, it was low hanging fruit) Higher-order functions give an engineer more control of the project making each step more understanding. The more understanding your codebase is to another engineer the fewer bugs will in inhabit in it!

thanks, Mike

PS: Jimmy Hoffa wiki

Top comments (0)