Hello! Welcome to the community
!
The result and error parameters come from the resolve and reject function call, respectively.
We got the data would be the content of the result variable, while Data not received would be the content of the error variable. In fact, since in this case you’re defining the promise and how it resolves or gets rejected, you could change the text to whatever you like and it would get received by the then or error callbacks:
const makeServerRequest = new Promise((resolve, reject) => {
// responseFromServer is set to false to represent an unsuccessful response from a server
let responseFromServer = false;
if(responseFromServer) {
resolve("Whatever you put here will be handed to the 'then' callback");
} else {
reject("Whatever you put here will be handed to the 'catch' callback");
}
});
makeServerRequest.then(result => { // This is the resolve("...")
console.log(result);
});
makeServerRequest.catch(error => { // This is the reject("...")
console.log(error);
});
Does it help?