[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/async_function [Back]  [Original]

async function - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

async function

Baseline
Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 4.

async function async .

async function statement async .

In this article

js
  async function (param0) {
    statements
  }

  async function (param0, param1) {
    statements
  }

  async function (param0, param1, /* ... */ paramN) {
    statements
  }

  async function name(param0) {
    statements
  }

  async function name(param0, param1) {
    statements
  }

  async function name(param0, param1, /* ... */ paramN) {
    statements
  }

arrow functions .

js
async (param) => expression;

async (param1, param2, ...paramN) => {
  statements;
};

name

. anonymous .

paramN

.

statements

.

async function async function , . async function async function , async function . async function IIFE() . functions .

js
function resolveAfter2Seconds(x) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

// async function   
const add = async function (x) {
  const a = await resolveAfter2Seconds(20);
  const b = await resolveAfter2Seconds(30);
  return x + a + b;
};

add(10).then((v) => {
  console.log(v); // 4  60 
});

// async function  IIFE 
(async function (x) {
  const p1 = resolveAfter2Seconds(20);
  const p2 = resolveAfter2Seconds(30);
  return x + (await p1) + (await p2);
})(10).then((v) => {
  console.log(v); // 2  60 
});

Specification
ECMAScript 2027 LanguageSpecification
# sec-async-function-definitions


Web Proxy Viewer  |  New URL  |  Original Page