WHY does this code NOT work when the values being passed are capitalized vs. lower case?
function booWho(bool) {
return typeof bool === 'boolean';
}
// test here
booWho(true);
returns: “true” and
function booWho(bool) {
return typeof bool === 'boolean';
}
// test here
booWho(false);
returns: “true”, but CAPITALIZE the value and we get
function booWho(bool) {
return typeof bool === 'boolean';
}
// test here
booWho(True);
returns: ‘True’ is undefined and
function booWho(bool) {
return typeof bool === 'boolean';
}
// test here
booWho(False);
returns: ‘False’ is undefined
Because true
and false
are the only booleans. True
is not the same as true
, since JS is case-sensitive.
2 Likes
ahhh,
so JS sees “True/False” as a String
… that makes sense.
True
and False
are undefined, because they don’t match any type. It is not a Boolean, but also not a String, because it doesn’t have quotes around it.
3 Likes
Expanding on what @BenGitter said. JS would see that as you trying to access a variable named True/False, so unless it’s defined with a value before hand, you get undefined.
2 Likes
I ran True/False with ’ ’ and " ", capitalized and lowercase, it came back as expected: false
thanks for the clarification