Boolean question

Tried googling it didn’t manage to find a concrete answer.
I passed this lesson, question how come it passes?

is it because in JS, if not stated otherwise it is true? if(responseFromServer)

const makeServerRequest = new Promise((resolve, reject) => {
// responseFromServer represents a response from a server
let responseFromServer;
if(responseFromServer) {
resolve("We got the data");
} else {  
reject("Data not received");
  **Your browser information:**

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

Challenge: Complete a Promise with resolve and reject

Link to the challenge:

The if statement does not check if it is “true”, it checks if it is “truthy”. “falsy” values are: false, 0, -0, 0n, empty strings, NaN, undefined, and null. Everything else is “truthy”.

1 Like

ah okay, so since its an empty string its “falsy” hence its true.

I’m not sure what is the “it” in that sentence.

In the example you provide, responseFromServer is declared but not initialized and never given a value so it would be undefined always so it would be falsy.

1 Like

Yes the variable was my referral, ty for your answer :slight_smile:

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