The Promise object allows you to make an asynchronous call to another function. The 'resolve' function is called when the asynchronous call is successful otherwise it falls back to 'reject' function.
#javascript#es6
// Create promisevarpromise=newPromise(function(resolve,reject){if(...){resolve("Promise resolved!");}else{reject(Error("Oh no!"));}});// Then you can use the promisepromise.then(function(result){console.log(result);// "Promise resolved!"},function(err){console.log(err);// Error: "Oh no!"});