Boo Who - is value a boolean primitive?

Hi guys,

I’m working through the Basic Algorithm challenges in JavaScript, and have come across what looks like a relatively simple one: check if a value is a primitive boolean.

I know to check the value with typeof, but I was checking if the value was equal to the keyword boolean, and I can see the solution says I need to check if it is equal to the string boolean.

I can’t figure out why? Why am I checking if it is equal to a string??

I’m sure it’s a simple answer but I am a novice so please go easy on me!


The typeof operator returns a string indicating the type of the unevaluated operand.

For example:

  • typeof 1 === 'number'
  • typeof undefined === 'undefined'
  • typeof true === 'boolean'
  • typeof null === 'object' (yep, really… due an old implementation detail that can’t be changed for fear of breaking the web)
1 Like

Thanks Lionel :slight_smile:

1 Like