Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js promise

let num = 2;
//call back function
const promis = new Promise(function (resolve, reject) {

  if (num > 5) {

    //this resolve method will send data to resoleveData variable
    resolve(" Problem resolved successfully")
  }
  else {
    //this reject method will send data to rejectData variable
    reject("sorry problem couldn't solve")
  }

})

promis.then(
    //resoleveData variable
    function (resolveData) {

    console.log(resolveData)
    
    }).catch(
    //rejectData variable
    function (rejectData) {

        console.log(rejectData)
    })
Source by programacionymas.com #
 
PREVIOUS NEXT
Tagged: #js #promise
ADD COMMENT
Topic
Name
7+2 =