Tell us what’s happening:
hello,
I am wondering my code isnt correct? I actually looked at a hint and, realized the typeof pathway, and solved the question. But I am still confused why my way is incorrect.
thank you!
Your code so far
function booWho(bool) {
if (bool = "true" | "false") {
return true
}
return false;
}
booWho(null);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.
No. bool == “true” || “false” only compares bool to “true”. Then, no matter what bool is, it ends up evaluating to true because a non-empty string is truthy. You aren’t comparing “false” to anything.
if (bool == true || false) will only be true if the variable bool is equal to the boolean value true. The || false does not add anything because false is false.
in this case it is better you use the scrict equality comparison ===, otherwise it would get true also for something like booWho("") (empty string, it is falsy, so "" == false is true; but if you use the strict equality "" === false this is false)
When you are using boleans, use always the strict equality operator