Tell us what’s happening:
I passed the test but I am not sure why I couldn’t pass it when I did ==
but when I did ===
I did. I know triple === is strict but why didn’t it pass when argument was 1
Your code so far
function booWho(bool) {
if(bool === true || bool ===false){
return true
}else{
return false
}
}
booWho(null);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Boo who
Link to the challenge:
What result are you expecting? When the argument is 1, it returns false which seems correct.
When I put ===
it shouldn’t print true expect for those, everything else is false
Your code says when the argument is true or false, it will return true. Everything else, false.
When you use ==, 1 casts to true. That’s why.
If i understand your question correctly you are asking why is it that the value of 1 in the function booWho is considered true when using == and false when using ===. This would be because 1 can be considered as a boolean value meaning true and 0 is also able to be considered a boolean value of false but when you use strict equality (===) 1 will be read as the number one not the boolean expression of true
Javascript will consider everything with a “value” as “true,” basically, if you do the looser == comparison. Look at JavaScript Booleans for more information. You are basically trying to say, “if its either true or false, return true, else return false,” but you need the === so that the code doesn’t try to convert the type of all your variables to boolean before the test.