For plain JS I typically prefer named functions for readability, but if using TypeScript I often notice that certain types of functions arise often - when a function itself can be considered a domain object (i.e. it has a specific call signature that is meaningful in the problem space), I usually use a function variable because that allows me to use a descriptive type that provides better context than just "function." For example, in a redux application you might have a type for a reducer:
Then, you can use the type to describe your reducer function:
// using traditional function keywordfunctionmyReducer(state,action){return{...state,...action};}// vs...typeMyReducer=Reducer<MyState,SomeAction>;constmyReducer:MyReducer=(state,action)=>({...state,...action});
Definitely more verbose, perhaps even less readable. But to me, it's worth it for the added type safety (YMMV)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For plain JS I typically prefer named functions for readability, but if using TypeScript I often notice that certain types of functions arise often - when a function itself can be considered a domain object (i.e. it has a specific call signature that is meaningful in the problem space), I usually use a function variable because that allows me to use a descriptive type that provides better context than just "function." For example, in a redux application you might have a type for a reducer:
Then, you can use the type to describe your reducer function:
Definitely more verbose, perhaps even less readable. But to me, it's worth it for the added type safety (YMMV)