- 最終更新
- 2026/08/17
3秒でわかる
非同期処理の完了待ちを上から下へ読める形で書くJavaScriptの構文。コールバックの入れ子をなくし、例外も try/catch でそのまま扱えます。
30秒図解
もう少し詳しく
どういうものか
async/await は、async をawait がawait は Promise が
なぜ必要か
通信や
具体例
async function loadUser(id) {
try {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error(`status ${res.status}`);
const user = await res.json();
return user;
} catch (e) {
console.error("取得に失敗", e);
return null;
}
}
// 独立した通信は同時に走らせる
const [a, b] = await Promise.all([loadUser(1), loadUser(2)]);上の 2 つの await はPromise.all で
つまずきやすいところ
最大のawait してしまい、10 件の取得にforEach の中で await をforEach はfor...of をawait をundefined として
覚え方
async はawait はasync をawait するか .then で


