Anonymous Function
Pronunciationuh-NON-uh-muhs FUHNGk-shuhn
Definition
A function defined without a name, usually passed directly as an argument or assigned to a variable.
Where you hear it
In code reviews, when discussing callbacks, event handlers, or functional programming patterns.
Examples
We used an anonymous function as a callback for the click event.
The sort method accepts an anonymous function to define custom ordering.
Pass a function with no name to map: numbers.map(n => n * 2).
Common mistake
Thinking anonymous functions cannot have parameters, when they accept inputs just like named functions.
Don't confuse with
Anonymous function vs. Arrow function. While all arrow functions are anonymous, not all anonymous functions are arrow functions because the latter have specific syntax and lexical scoping rules.
Say it at work
- In a meeting or chat
I think we can just pass an anonymous function here instead of defining a separate helper function.
- In an email or ticket
Please refactor this block to use an anonymous function for the filter criteria to improve readability.
Keep exploring
More in Programming Fundamentals