ES8 - Async Functions

This tutorial covers ES8 Async Functions tutorials, examples introduced to latest javascript features, in ES8, ES2017, with examples.

javascript Async Functions

Async functions are introduced to simplify the promised based operations. Async keyword introduce to simply asynchronous operations.

Let’s see an example before and after ES8 to javascript features.

.then((response) => {
}, (error) => {

The same can be rewritten using Async function, asyc functions are returns promises, so

async getEmployes(url) => {
  try {
    const response = await axios.get('/api/employes');
    return response;
  } catch (error) {
getEmployes(url).then(emps => {

These makes easier to read the code looks like synchronous code, Await is not compulsory

Support This will support in latest browsers To support in older browsers, enable the following plugins in your project

  • polyfill
  • babel plugin