Boo Who Boolean Diet WTF?

Boo Who Boolean Diet WTF?
0

#1

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


#2

Because true and false are the only booleans. True is not the same as true, since JS is case-sensitive.


#3

ahhh,
so JS sees “True/False” as a String
… that makes sense.


#4

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.


#5

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.


#6

I ran True/False with ’ ’ and " ", capitalized and lowercase, it came back as expected: false

thanks for the clarification