Lexicon
⌘K
Explore
ExploreGuidesNotes
WriteMy Library
Sign in
Browse

Networking

  • OSI Model
  • TCP vs UDP
  • TCP/IP Model
  • Layer 2 & Layer 3 Networking

Programming

  • Start Here — How to Solve a Problem
  • From if/else to DSA — The Whole Path
  • Problem Solving
  • DSA Practice — Learn by Solving
  • C Programming
  • Python

Bug Bounty

  • Only Bug Bounty Checklist You'll Ever Need!!!
  • Only Bug Bounty Checklist You'll Ever Need!!! V2

My Notes

  • Python Conditional Statements - The Complete Breakdown
  • Python Data Types - The Complete Breakdown
  • Python Dictionaries - The Complete Breakdown
  • Python Exception Handling - The Complete Breakdown
  • Python Functions - The Complete Breakdown
  • Python Lists vs Arrays — The Real Story
  • Python Loops - The Complete Breakdown
  • Python OOP - The Complete Breakdown
  • The f Thing in Python - f-strings

Python

  • Python String Manipulation Functions - Full Reference
New noteSuggest a guide

Lexicon

a personal knowledge base

JavaScript

JavaScript async and await

scorpionxdevUpdated 6/28/2026 · 1 min read · 0 views
PDFHistory

async/await is syntax sugar over Promises that lets asynchronous code read top to bottom like normal code. Under the hood it is still Promises.

The basics

An async function always returns a Promise. await pauses inside that function until the awaited Promise settles.

async function getUser(id) {
  const res = await fetch(`/api/users/${id}`);
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  return res.json();
}

Error handling

Wrap awaits in try/catch instead of .catch() chains.

try {
  const user = await getUser(42);
  console.log(user.name);
} catch (err) {
  console.error('failed to load user', err);
}

Do not serialize by accident

Awaiting inside a loop runs requests one after another. If they are independent, fire them together with Promise.all.

// Slow: each await waits for the previous one
for (const id of ids) {
  results.push(await getUser(id));
}

// Fast: all requests in flight at once
const results = await Promise.all(ids.map(getUser));

Parallel vs settled

  • Promise.all rejects as soon as any one rejects
  • Promise.allSettled waits for every promise and reports each result, good when partial failure is acceptable

Common gotcha

forEach does not await. Use a for...of loop or map with .

Reading progress0%
scorpionxdev@scorpionxdev
Promise.all
// This does NOT wait, the callback is async but forEach ignores the promise
items.forEach(async (item) => { await save(item); });

0 comments

Sign in to join the discussion.