function stepPromise(stepName) {
return new Promise((resolve) => {
setTimeout(() => {
console.log(`${stepName} completed`);
resolve();
}, 1000);
});
}
// Promise chaining to avoid callback hell
stepPromise("Step 1")
.then(() => stepPromise("Step 2"))
.then(() => stepPromise("Step 3"))
.then(() => console.log("All steps completed (with Promise)"));
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter