Core JavaScript / Higher Order Functions
Higher-Order Functions
Functions that take other functions as input, or return them as output.
A higher-order function treats other functions as ordinary values - accepting them as arguments, or returning them as results. `map`, `filter`, and `addEventListener` are all higher-order: you hand them a function and they decide when to call it. This is the same mechanism that makes callbacks, and later promises, possible.
Codeeditable — Run and Step both follow your edits
Loading...
Console
Output will appear here
Visualization
Result
Press Step to watch each line's result appear here
Why?
withLogging never knows what add actually does - it just wraps any function with a log statement before calling it. That's what makes it higher-order: it operates on functions generically.