Introduction
When we say the word “bake”, it calls to mind a familiar subroutine— preheating an oven, putting something into an oven for a set amount of time, and finally removing it. This allows us to abstract away a lot of the details and communicate key concepts more concisely.
Higher-order functions are functions that accept other functions as arguments and/or return functions as output. This enables us to build abstractions on other abstractions, just like “We hosted a birthday party” is an abstraction that may build on the abstraction “We made a cake.”
Functions as Data
JavaScript functions behave like any other data type in the language; we can assign functions to variables, and we can reassign them to new variables.
In JavaScript, functions are first class objects. This means that, like other objects you’ve encountered, JavaScript functions can have properties and methods.
Functions are special because we can invoke them, but we can still treat them like any other type of data.
busy is a variable that holds a reference to our original function.
Functions as Parameters
As you know, a parameter is a placeholder for the data that gets passed into a function.
A higher-order function is a function that either accepts functions as parameters, returns a function, or both! We call functions that get passed in as parameters callback functions. Callback functions get invoked during the execution of the higher-order function.
We wrote a higher-order function higherOrderFunc that accepts a single parameter, param. Inside the body, param gets invoked using parentheses. And finally, a string is returned, telling us the name of the callback function that was passed in.
/* Вызов функции происходит через приписывание в конце идентификатора скобочки "()". Ранее, когда мы сокращали название функции через присвоение её идентификатора константе, мы добавляли к совокупности указателей, ссылающихся на функцию, ещё одно имя. Написание скобочек запустило бы выполнение функции, что не требовалось в момент расширения пространства указателей. */