Promise in JavaScript - IndianTechnoEra
Latest update Android YouTube

Promise in JavaScript

Promises give us a way to make sense out of asynchronous behavior. When making an asynchronous request, one of two things can happen: everything goes as we hope or there’s an error. This can happen in a number of different ways. 

Promise in JavaScript | JavaScript


For example, we could try several ways to obtain the data to reach success. We also could receive mul‐ tiple types of errors. Promises give us a way to simplify back to a simple pass or fail.


Example 1: If student pass then promise resolve and return .then
var myPromise = new Promise(function (resolve, reject) {
  const x = 'Pass'
  if (x == 'Pass') {
    resolve()
  } else {
    reject()
  }
})

myPromise
  .then(function () {
    console.log('OMG!, you also pass the exam. Lelo bete mobile lelo')
  })
  .catch(function () {
    console.log('Hufffff! Mujhe to pata that ')
  })

  //OMG!, you also pass the exam. Lelo bete mobile lelo

Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.