Understanding JavaScript Promises: Pending, Fulfilled, Rejected

Let's Understand JavaScript Promises If you’ve ever dealt with asynchronous code in JavaScript, you’ve probably heard of Promises. Think of a Promise like a real-life promise it can either be kept or broken. Here’s how it works 👇 • Pending: The promise is still waiting for something to finish (like fetching data). • Fulfilled (Resolved): The task succeeded! You get the result using .then(). • Rejected: Something went wrong you handle the error with .catch(). 🧠 Example: new Promise((resolve, reject) => { const success = true; success ? resolve("Data received!") : reject("Error occurred!"); }) .then(console.log) .catch(console.error); Promises make asynchronous code cleaner and easier to manage no more callback hell! 💬 How did you first learn about Promises? Drop your favorite example below! #JavaScript #WebDevelopment #AsyncProgramming #Learning #Coding

  • timeline
Ioan Tudor

Founder @ BetLogic | AI-powered football match analysis platform - Freelance Frontend Developer

6mo

Don't forget about the fact that promise have an under the hood object - [[PromiseResult]] - [[PromiseState]] - [[PromiseReaction]] (depends if it's fullfilled or rejected) which the result is passed through Reaction using .then to edit the result

Like
Reply

To view or add a comment, sign in

Explore content categories