298 words, 2 min read

In modern TypeScript codebases, you’ll often see functions defined like this:

const doSomething = (): void => {};

instead of:

function doSomething(): void {}

Both are valid. But there are good reasons why many teams prefer the const + arrow function style as a default.

Predictable execution order

Function declarations are hoisted:

doSomething(); // Works
function doSomething(): void {}

This can hide ordering problems and make large modules harder to reason about.

Arrow functions assigned to const are not callable before initialization:

doSomething(); // ReferenceError
const doSomething = (): void => {};

This makes execution order explicit and avoids subtle refactoring issues.

Immutability by default

Using const makes it clear the function reference should not change:

const doSomething = () => {};

Treating functions as immutable values aligns well with modern TypeScript practices and reduces accidental reassignment.

Safer this behavior

Arrow functions use lexical this, meaning they capture this from the surrounding scope.

class Example {
value = 42;
method() {
setTimeout(() => {
console.log(this.value); // Works
});
}
}

With a traditional function, this would be undefined or unexpected unless manually bound. Arrow functions eliminate an entire class of common JavaScript bugs.

Better fit for functional patterns

Arrow functions integrate naturally with higher-order functions:

const double = (x: number) => x * 2;
const result = numbers.map(double);

This style scales well in functional and compositional code.

When to use function declarations

Function declarations still make sense when:

  • You intentionally rely on hoisting
  • You want a clearly named recursive function
  • You define class methods

They’re not wrong — just more situational.

Conclusion

Using const with arrow functions promotes:

  • Explicit execution order
  • Immutability
  • Safer this semantics
  • Consistency across modern codebases

For most TypeScript projects, it’s a sensible default. Use function deliberately when its behavior is exactly what you need.