Tag: boolean

FCC Bonfire Series 131: Sum All Prime

Today, we tackle a new challenge. This time, we are going to start simple, and then challenge our brains to optimize our function a little. I won’t be giving you the fastest answer to this problem, but […]

FCC Bonfire Series 126: Boo who

We are going to get it done FAST today. This next bonfire, Boo Who will have us write a function that given a value, return true if that value is a boolean primitive (true or false) and false otherwise.

Remember that we are checking for primitive boolean values, not truthy or falsy ones.

Let’s get straight to the action by using the typeof operator. Remember that typeof operates over a value and returns it’s type:

typeof 'hello world';  //-> "string"
typeof 4;  //-> "number"
typeof true;  //-> "boolean"

Let’s start by using a conditional if statement:

function boo(value) {
  if (typeof value === 'boolean') {
    return true;
  } else {
    return false;
  }
}

Pretty simple isn’t it! Let’s make it a little cleverer (I just found out that cleverer is an actual word).