JS FUNCTIONSChapter 5 · JS Functions and Classes
Higher-Order Functions
A higher-order function takes a function as an argument, returns one, or both. You already use them: map, filter and forEach all take a function. Writing your own lets you capture a pattern once, such as "do this n times" or "only run this once", and reuse it with any behaviour plugged in.
Worked example
How it reads
repeattakes the action as a parameter and calls itoncereturns a new function that remembers whether it already ran...argsforwards whatever arguments the caller passes

Cloud tip: When two functions differ only in one small step, pass that step in as a function.


