45
export default async function () {

};

or

export default async () => {

};

Which one is preferred when exporting a default function and why?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
basickarl
  • 37,187
  • 64
  • 214
  • 335

1 Answers1

45

The first one is generally preferred. It's a declaration, not an expression value, which has subtle advantages. And it can easily be named if you want, which is a good practice. Also, arrow functions have a few disadvantages in certain situations, so unless you absolutely need them to preserve a this value (etc.) you'd rather avoid them. Saving 5 characters to type is hardly worth it.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375