Using an if statement in this lesson

Hi folks,

In this lesson:

I tried to answer it using an if statement:

function booWho(bool) {
    
    if(typeof bool === "boolean"){
      return bool;
    }

   //return typeof bool === "boolean";
}

booWho(null);

But the if statement doesn’t working the commented code does but I struggle to understand - why the if statement doesn’t work - should it?

Cheers :slight_smile:

you should return true if it is a boolean, or false if it is not

instead if it is a boolean you are returning the boolean (so it can be either true or false) and if it is not a boolean you are returning nothing, so it returns undefined by default

3 Likes

Thank you that makes sense to me now feel free to close. :slight_smile: