How does curry use closures in JavaScript?
Each partial call of a curried function returns a new function that closes over the accumulated arguments. The closure keeps the arguments alive between calls. When enough arguments are collected, the original function is called.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in The Relationship Between Closures and Higher-Order Functions
Closures are what make HOFs work. When a HOF returns a function, the returned function closes over the HOF's local variables. This lets the returned function access those variables later, even after the HOF has returned.
Because of closures. The returned function holds a reference to the HOF's lexical environment. As long as the returned function exists, the environment (and its variables) cannot be garbage collected.
memoize is a HOF that returns a function. The returned function closes over a cache object. Each call checks and updates the cache. The cache persists across calls because of the closure.
Still have questions?
Browse all our FAQs or reach out to our support team
