Basic Algorithm Scripting - Boo who

Could someone please explain to me why booWho(false) does not return true?
it is the only check that isn’t passing.
Ps: i know that i can use 'type of ’ but i still want to understand why booWho(false) does not returns true.

function booWho(bool) {
  if(bool === true || false){
  return true;
  }
  else{
    return false;
  }
}

console.log(booWho(null));

Your browser information:

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

Challenge: Basic Algorithm Scripting - Boo who

Link to the challenge:

This is not doing what you think it is. There are imaginary parentheses in there. It is really:

if (bool === (true || false)) {

What does the expression true || false always return?

If you want to take this approach then think of the if statement as:

“if bool equals true OR bool equals false”.

1 Like

I had to read this many times to understand,but that i did.
Thank you very much

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