ES6 - Complete a Promise with resolve and reject

Why is it that when I enter ‘=== true’ in my if statement the code does not pass?
Describe your issue in detail here.

The concept of the promise is not what I do not understand. I am more so curious as to why my code did not pass when I entered
“if (responseFromServer === true)”

why is it that the code did not pass when I completed the boolean vs letting the default value be implied??
thanks in advance

Your code so far

const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer represents a response from a server
  let responseFromServer;
  if(responseFromServer === true) {
    resolve("We got the data");
    // Change this line
  } else {  
    reject("Data not received");
    // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: ES6 - Complete a Promise with resolve and reject

Link to the challenge:

You never initialized that variable, so it cannot be ‘true’.

1 Like

thank you, I have an additional question. If declared, but not initialized variables are “undefined”, how does JS know that I want the if statement to be for “true” and the else for “false”? I dont really understand that

unless it is just checking if the variable exists at all?

I’m not really sure what’s happening in that code.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.