Can you pass a function as an argument in JavaScript?
Yes. Passing functions as arguments is how callbacks work. setTimeout, map, filter, fetch.then, and event listeners all accept functions as arguments.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Functions as First-Class Citizens in JavaScript
Functions are treated like any other value. They can be assigned to variables, passed as arguments, returned from other functions, stored in data structures, and have a type (typeof is 'function').
Yes. A function that returns another function is called a higher-order function. The returned function often captures the outer variable environment, creating a closure.
'function'. Functions are a distinct type, but under the hood they are callable objects. They can even have their own properties, though this is rarely useful.
Still have questions?
Browse all our FAQs or reach out to our support team
