Promises are used to handle asynchronous operations. A promise has three states: pending
, resolved
, and rejected
.
const promise = new Promise((resolve, reject) => { let success = true; if (success) resolve("Promise resolved!"); else reject("Promise rejected!"); }); promise .then((message) => console.log(message)) .catch((error) => console.error(error));
codification school Changed status to publish November 29, 2024