What is Promise in JS?

In JavaScript, a Promise is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

Promises provide a more elegant way to handle asynchronous code compared to callbacks, making it easier to read and maintain

const myPromise = new Promise((resolve, reject) => {
const success = true; // Simulate success or failure
if (success) {
resolve("Operation succeeded!");
} else {
reject("Operation failed.");
}
});