Thuta Learning
JavaScript
AdvancedProgrammingbeginner

JS Promises

Promises များသည် asynchronous operation တစ်ခု၏ နောက်ဆုံး result ကို ကိုယ်စားပြုသော object ဖြစ်သည်။ Operation ပြီးဆုံးသောအခါ (succeed or fail) .then() (အောင်မြင်လျှင်) နှင့် .catch() (ကျရှုံးလျှင်) methods များဖြင့် ထို result ကိုကိုင်တွယ်နိုင်သည်။

javascript
const myPromise = new Promise((resolve, reject) => {
  let success = true;
  if (success) {
    resolve("The operation was successful!");
  } else {
    reject("The operation failed.");
  }
});

myPromise
  .then((message) => {
    console.log(message);
  })
  .catch((error) => {
    console.error(error);
  });
You should see
The operation was successful!
JS Promises | Thuta Learning