Language concepts

async function declaration

Try the free JavaScript compiler

Declares a function whose calls produce promises. Normal returned values resolve the result; thrown errors reject it. Await can suspend its evaluation.

Formal Syntax & Structure

javascript syntaxjavascript
async function name(...args) { /* body */ }

Working Example

Example Snippetjavascript
async function run() { console.log("enter"); const n = await 3; console.log(n); return n * 2; }run().then(console.log);console.log("outside");
JavaScript Reference