Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 21
    The OP appears to be looking for a named, async, arrow function which is the one syntax you do not show. Commented Mar 22, 2017 at 23:19
  • 72
    Actually, const foo = async () => {} creates a named async function named foo. It's entirely possible to do named functions this way (just no hoisting). In ES2016+ assignment of an anonymous function to a variable names it after the variable if it is declared there. Commented Mar 22, 2017 at 23:55
  • 9
    @BenjaminGruenbaum Please don't call it named function. In js, a named anonymous function is a very specific syntax foo = function bar () {} that was created to replace arguments.callee when writing recursive anonymous functions. What you have there is a variable named foo that is a reference to a function. Commented Jun 4, 2017 at 2:32
  • 28
    @slebetman since ES2015 when you do const foo = async () => {} the name of the function is set to foo - ecma-international.org/ecma-262/6.0/… and ecma-international.org/ecma-262/6.0/… - see discussion in esdiscuss.org/topic/… Commented Jun 4, 2017 at 19:03
  • 2
    @FarisRayhan It's just as with other constants, the reference of the variable somefunction cannot be changed after it is set. (It points to your anonymous async function.) Commented Jul 24, 2018 at 12:16