Surya JS Journey
Learn JavaScript through concepts, code, and guided practice.
A focused workspace for concept study, interactive examples, visual explanations, and challenge solving.
Promise
Promises represent the eventual result of asynchronous operations and make async flows easier to compose.
A promise can be pending, fulfilled, or rejected. It gives you a structured way to react when asynchronous work finishes. Promises are the foundation for chaining async operations and for using `async` and `await` cleanly in modern JavaScript applications.
Explanation
A promise can be pending, fulfilled, or rejected. It gives you a structured way to react when asynchronous work finishes. Promises are the foundation for chaining async operations and for using `async` and `await` cleanly in modern JavaScript applications.
Key Points
- A promise represents a future value, not the value itself right now.
- `.then()` handles fulfilled values, and `.catch()` handles failures.
- `async` and `await` are built on top of promises.
Common Mistakes
- Trying to return async values synchronously from outside a promise chain.
- Forgetting to handle rejected promises.
- Mixing callbacks and promise chains inconsistently.
Practice Workspace
promise.js
Edit the code, run it in the browser, and inspect the console output below. Reset restores the original snippet for this page.
Editor
7 lines
Output
0 entries
Mode
practice
Workspace Notes
Changes stay local until you run the code. Reset restores the original snippet immediately for another pass.
Editor Actions
Use the editor to explore the example, then run it to inspect the console.
Run the code to see output here.
Expected Output
Lesson loadedContinue in Playground
Open this concept example in the shared playground to keep experimenting without leaving the broader workspace flow.
Open in PlaygroundRelated Concepts
Practice Challenges
Predict the event loop output
8 minRead mixed synchronous, promise, and timer code and determine the true execution order.
Fix a broken promise chain
12 minRepair an async flow so success and failure are handled in a predictable order.
Refactor a promise chain with async/await
10 minRewrite a chained async flow using async/await while preserving the final output order.