Promises — Complete Guide
Promises — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of JavaScript Tutorial on Toolliyo Academy.
On this page
JavaScript Tutorial · Lesson 43 of 100
Promises
Basics ✓ → Objects & data ✓ → Async & DOM → Advanced → Tools → Projects
Intermediate · 3 — Async & DOM · ~6 min · JS Async JavaScript
What is this?
A Promise represents work that finishes later — loading data from a server. It will succeed (resolve) or fail (reject). You handle results with .then() and .catch().
Why should you care?
Browsers cannot freeze while waiting for a network response. Promises let other code keep running.
See it live — copy this example
Paste into an HTML file or the browser console (F12). Use Run below when the live editor is available.
function wait(ms) {
return new Promise((resolve) => {
setTimeout(() => resolve("Done after " + ms + "ms"), ms);
});
}
wait(500).then((msg) => console.log(msg));
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- new Promise takes a function with resolve.
- setTimeout runs after 500ms, then resolve sends the message to .then().
Practice next
- Run wait(500).then and observe delay.
- Chain two waits in sequence.
- Add .catch on a rejecting promise.
- Return Promise.all on two wait calls to run in parallel.
- Reject intentionally and log in catch with a custom message.
Remember
Promise = future value .then for success, .catch for errors Used by fetch and timers
ScriptVerse parallel fetch
Dashboard loads accounts and notifications with Promise.all before hiding the skeleton loader.
Outcome: Promises coordinate multiple API calls without callback nesting.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!