Passing different functions as arguments to achieve different behaviors. For example, process(data, sortAscending) vs process(data, sortDescending). The function (strategy) is passed as an argument.
Functions as Arguments and Return Values in JavaScript
What is the strategy pattern in JavaScript using functions?
The answer
More FAQs in Functions as Arguments and Return Values in JavaScript
Yes. This is a callback. setTimeout, map, filter, reduce, event listeners, and fetch.then all accept functions as arguments. The receiving function (higher-order) calls the callback at the right time.
Yes. A function that returns another function is a higher-order function (a function factory). The returned function often closes over the outer function's variables, creating a closure.
A function that takes a function as an argument, returns a function, or both. Examples: map, filter, reduce, compose, curry, partial, setTimeout, and event listeners.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.