How to create a promise in javascript?

Promises in JavaScript represent a value which might be available now, or in the future, or never.

Example:


  let promise = new Promise(function(resolve, reject) {
      setTimeout(function() {
          resolve("Done!");
      }, 1000);
  });

  promise.then(function(value) {
      console.log(value);  // Outputs: Done!
  });
  

Beginner's Guide to JavaScript