Something important to know is that a Promise returns straight away, but the result is not available straight away. Promises are also known as thenables, because you need to register a callback with its then() method once the data has been received, like so:
const promise = new Promise((resolve, reject) => { // either call resolve() if we have a success or reject() if it fails });// the 'promise' variable points to a construct // that will eventually contain a valuepromise((data) => { // <- registering a callback on then() // our data has arrived at this point})
In the preceding code, we demonstrated how to create a promise and how to register it with the then() method. The promise variable instance contains a construct that is ...