Hot take - functions > constants in js
Hot take - functions > constants in js
Hot take - functions > constants in js
Hot take - functions > constants in js
2025-03-13

I see less of actual function declarations in js codebases these days, and fat arrows stored to constants are more the norm. I still don't know why. Is this just a react-ism from the change to using hooks? This declaring of functions inside components also means that on each re-render the functions get re-declared, instead of once if those functions were at the top level.

In some codebases I've seen, you end up with many of these anonymous functions stored in constants, all of which rely on the scope of the react component, sort of as if it was a class (which it isn't, to confirm). This makes reading the actual component kind of tricky; I'd rather have top level, functional functions, outside of the react component, take in data, do something with it, and return data, but I hardly ever see this.

On a more petty note, it seems worth it alone to declare functions over constants to cut down on the visual noise while searching for symbols in my editor.