JavaScriptEasy
What are Promises and how do they work?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Promises in JavaScript are objects that represent the eventual completion (or failure) of an asynchronous operation and its resulting value. They have three states: pending, fulfilled, and rejected. You can handle the results of a promise using the .then() method for success and the .catch() method for errors.
js
let promise = new Promise((resolve, reject) => {
// asynchronous operation
const success = true;
if (success) {
resolve("Success!");
} else {
reject("Error!");
}
});
promise
.then((result) => {
console.log(result); // 'Success!' (this will print)
})
.catch((error) => {
console.error(error); // 'Error!'
});
