What is meant by result comes from the argument given to result?

I don’t understand what is meant by result comes from the argument given to the resolve method. someone some explain this better to me. thanks

Your code so far


const makeServerRequest = new Promise((resolve, reject) => {
 // responseFromServer is set to true to represent a successful response from a server
 let responseFromServer = true;
   
 if(responseFromServer) {
   resolve("We got the data");
 } 
 makeServerRequest.then(result =>{
  console.log(result);
 });
/* else {  
   reject("Data not received");
 }*/
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Handle a Fulfilled Promise with then

Link to the challenge:

Hello there,

Whatever is given as the argument to the resolve callback (in the above case - "We got the data"), will be the value of the parameter in the resolved promise function.

const myPromise = new Promise((res, rej) => {
  res("String I want to pass, if data is resolved");
}

myPromise.then(resultParameter => {
  console.log(resultParameter); // returns "String I want to pass, if data is resolved"
}

In the above, "String I want to pass, if data is resolved" is the argument given to the res (same as resolve method). And, this argument’s value is the passed to the callback function of the promise, where I stored it as resultParameter.

Remember, the parameter namespaces can be anything you want - does not need to be result.

I hope this helps

1 Like