- 最終更新
- 2026/08/17
3秒でわかる
あとで成功か失敗が決まる値を包むJavaScriptのオブジェクト。通信やファイル読み込みの結果を await や .then() で受け取るための土台です。
30秒図解
もう少し詳しく
どういうものか
Promise はfetch() や Node.js の fs/promises、setTimeout を包んだ関数など、
なぜ必要か
Promise が.catch() 一箇所に
具体例
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function main() {
const res = await fetch("https://api.example.com/users/1");
if (!res.ok) throw new Error("取得に失敗しました");
const user = await res.json();
await wait(500);
console.log(user.name);
}
main().catch((err) => console.error(err.message));await は
つまずきやすいところ
await をPromise { <pending> } がforEach のawait をfor...of、並列でPromise.all() を使う.then() の中で return を.then() にundefined になるcatch の似た用語との違い
| 書き方 | 特徴 |
|---|---|
| コールバック | 引数に |
| Promise | 結果を包む値。.then() で |
| async / await | Promise を |
async 関数は
覚え方
「引換券」と

