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;
}
console.log(booWho());
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.
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).