Hacker News new | ask | show | jobs
by chatmasta 1125 days ago
If you're only consuming the variable once, and it's inside a declarative syntax like JSX, then I'd argue it's more readable to use an anonymous function, because the reader doesn't need to look elsewhere, and the function is defined in the same place where it's evaluated. And you don't need to bother thinking up a name for a variable, which could lead you to prematurely generalize.

Personally, most of the time I assign to a variable. But I do think there are cases where the IIFE is an appropriate and more elegant approach.