--- title: async function 표현식 slug: Web/JavaScript/Reference/Operators/async_function browser-compat: javascript.operators.async_function translation_of: Web/JavaScript/Reference/Operators/async_function --- <div>{{jsSidebar("Operators")}}</div> <p><strong><code>async function</code></strong> 키워드는 표현식 내에서 <code>async</code> 함수를 정의하기 위해 사용됩니다.</p> <p>또한 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">async function statement</a>을 사용하여 async 함수를 정의할 수 있습니다.</p> <h2 id="문법">문법</h2> <pre class="syntaxbox">async function [<em>name</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) { <em>statements </em>}</pre> <p>ES2015에서와 같이 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a>를 사용해도 됩니다.</p> <h3 id="인수">인수</h3> <dl> <dt><code><var>name</var></code></dt> <dd>함수 이름. 생략가능하며 이경우함수는 <em>anonymous</em> 형식임 이름은 함수 몸체에 대해 지역적으로 사용.</dd> <dt><code><var>paramN</var></code></dt> <dd>함수에 전달될 인수의 이름.</dd> <dt><code><var>statements</var></code></dt> <dd>함수 몸체를 구성하는 명령문들.</dd> </dl> <h2 id="설명">설명</h2> <p><code>async function</code> 표현식은 {{jsxref('Statements/async_function', '<code>async function</code> 선언')}} 문법과 유사하며, 거의 동일합니다. <code>async function</code> 표현식과 <code>async function</code> 선언문의 주요 차이점은 익명함수로써의 사용 여부로, <code>async function</code> 표현식은 함수 이름을 생략하면 익명함수를 만듭니다. <code>async function</code> 표현식은 {{Glossary("IIFE")}}(즉시실행함수)로 사용할 수 있습니다. <code><a href="/en-US/docs/Web/JavaScript/Reference/Functions">functions</a></code>문서를 참고하세요.</p> <h2 id="Examples">Examples</h2> <h3 id="Simple_example">Simple example</h3> <pre><code>function resolveAfter2Seconds(x) { return new Promise(resolve => { setTimeout(() => { resolve(x); }, 2000); }); }; var add = async function(x) { // async function 표현식을 변수에 할당 var a = await resolveAfter2Seconds(20); var b = await resolveAfter2Seconds(30); return x + a + b; }; add(10).then(v => { console.log(v); // 4초 뒤에 60 출력 }); (async function(x) { // async function 표현식을 IIFE로 사용 var p_a = resolveAfter2Seconds(20); var p_b = resolveAfter2Seconds(30); return x + await p_a + await p_b; })(10).then(v => { console.log(v); // 2초 뒤에 60 출력 });</code></pre> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('ESDraft', '#sec-async-function-definitions', 'async function')}}</td> <td>{{Spec2('ESDraft')}}</td> <td>Initial definition in ES2017.</td> </tr> </tbody> </table> <h2 id="Browser_compatibility">Browser compatibility</h2> <div>{{Compat}}</div> <h2 id="See_also">See also</h2> <ul> <li>{{jsxref("Statements/async_function", "async function")}}</li> <li>{{jsxref("AsyncFunction")}} object</li> <li>{{jsxref("Operators/await", "await")}}</li> </ul>