JavaScript Async Functions Explained

JavaScript Logo

Async Functions – Declares an async function, allowing use of `await` inside. Returns a Promise implicitly.

๐Ÿ‘‰ Syntax

async function fetchData() {
  const res = await fetch('/api');
  return res.json();
}

๐Ÿงช Example

async function getUser() {
  let res = await fetch('/user');
  let data = await res.json();
  console.log(data);
}

Comments