Basic Async/Await in JavaScript

From the Async JavaScript cheat sheet · Async/Await · verified Jul 2026

Basic Async/Await

Modern syntax for writing asynchronous code that looks and behaves like synchronous code

javascript
// Async function
async function getData() {
  const response = await fetch('/api/data');
  const data = await response.json();
  return data;
}

// Error handling
async function safeGet() {
  try {
    const data = await getData();
    console.log(data);
  } catch (error) {
    console.error('Failed:', error);
  }
}

// Parallel execution
async function parallel() {
  const [a, b] = await Promise.all([
    fetch('/api/a'),
    fetch('/api/b')
  ]);
}
💡 Async/await is syntactic sugar built on top of promises
⚡ Makes asynchronous code look and behave like synchronous code
⚠️ Can only use await inside async functions
✅ Easier to read and debug than promise chains

More JavaScript tasks

Back to the full Async JavaScript cheat sheet