SyntaxStudy
Sign Up
JavaScript Introduction to Promises
JavaScript Beginner 4 min read

Introduction to Promises

Promises

A Promise represents a value that will be available in the future. It is in one of three states: pending, fulfilled, or rejected.

Example
const p = new Promise((resolve, reject) => {
  setTimeout(() => resolve("done!"), 1000);
});
p.then(val => console.log(val))   // "done!"
 .catch(err => console.error(err))
 .finally(() => console.log("always runs"));
Pro Tip

Always attach a .catch() — unhandled rejections crash Node and log warnings in browsers.