Published on

JavaScript Method Naming Convention for Async Functions

Authors

In a JavaScript framework I was looking at I noticed how async method names are suffixed with Async.

For example if we have an asynchronous method called getData, in this framework it would be called getDataAsync.

Having worked on JavaScript apps for the last while this convention makes sense since when using a method it is not clear if the method is async or not. For instance if I have:

async function getData() {
  // ...
}

I then use this in another class:

// ...
const data = getData()
// ...

Oops I forgot to await this or handle this properly. If you do not have intellisense or linting you will not realize you have not handled an async method properly. But if you have a convention where you name a method with Async in the name ,to indicate this, you can more easily pick it up and handle it properly. If I change the original function definition to:

async function getDataAsync() {
  // ...
}

I can now clearly see when I am calling this method that it is async without having to look at what the method's code looks like.