What is Promise

Promise is used to handle async operation and it’s resulting value will be success or failure.
A Promise has basically three state
pending: initial state, neither fulfilled nor rejected.

fulfilled: meaning that the operation completed successfully.
it uses resolve method for this

rejected: meaning that the operation failed.
it is use reject method for this.

function checkPostiveNumber (number) {
 
  return new Promise((resolve, reject) => {

  try { 
         if((number<0))
         {
            throw new Error(` ${number} is not a postive number` );
         } 
        } catch(msg) {
            reject(`Error in callback ${msg}`); 
        }

        resolve(`${number} is a postive number`)
});
}

let data=checkPostiveNumber(1);
console.log(data);
Promise {: “1 is a postive number”}
__proto__: Promise
[[PromiseStatus]]: “resolved”
[[PromiseValue]]: “1 is a postive number”