Explanation needed!

Tell us what’s happening:
Like many others, this is what I did and it works perfectly. BUT, why does it not work for only 0 and 1, when the non-strict equal sign == is used?

Your code so far

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


Your browser information:

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

Challenge: Boo who

Link to the challenge:

Hello and welcome to the freeCodeCamp community~!

When you use the loose equality operator ==, JavaScript will try to convert types for you. 0 and 1 are used to represent true/false in binary (and some programming languages, I believe) and JavaScript can convert them to false or true, which passes a == check. It fails a strict equality === because the data types do not match (JavaScript will not convert types here).

1 Like

hi. the problem is that you should check them with strict equality to ensure that type will be matched too, as the challenge asked.

Hi @xbeeee!

I have edited your post with [spoiler] and [/spoiler] tags on the line above and below your solution code.

This is for those users in the forum who have not done this challenge yet.


1 Like