Promise
ELI5 — The Vibe Check
A Promise is JavaScript's way of saying 'I'll give you a value eventually — it's not ready yet, but I promise.' Instead of blocking everything while waiting for data, a Promise lets you say 'when this is done, do this next thing.' It has three states: pending, resolved (fulfilled), or rejected.
Real Talk
A Promise is a JavaScript object representing the eventual completion or failure of an asynchronous operation. It provides .then() for success handlers, .catch() for error handlers, and .finally() for cleanup. Promises form the foundation of async/await syntax and are used throughout browser APIs (Fetch, IndexedDB, etc.).
Show Me The Code
// Creating a Promise
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))
// Chaining
fetch('/api/data')
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err))
// Promise.all — run in parallel
const [users, posts] = await Promise.all([fetchUsers(), fetchPosts()])
When You'll Hear This
Promise.all lets you run multiple async operations in parallel.,A rejected Promise without a .catch() causes an unhandled rejection error.,Async/await is just syntactic sugar over Promises.
Related Terms
Async/Await
Async/await is syntactic sugar that makes Promises look like normal, readable code. Instead of chaining .then().then().
Callback
A callback is just a function you pass to another function, saying 'when you're done, call this.
Event Loop
JavaScript can only do one thing at a time (single-threaded), but the Event Loop is the trick that makes it seem like it can multitask.
Fetch
Fetch is the modern, built-in JavaScript way to make HTTP requests to APIs. You tell it a URL, it goes and gets the data, and you handle the response.