# How to implement is Boolean function in JS?

**URL:** <https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826>\
**Category:** General\
**Created:** [May 21, 2016, 5:23pm UTC](https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826 "2016-05-21T17:23:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nameToReachPeople](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nametoreachpeople/32/10814_2.png) [@nameToReachPeople](https://forum.freecodecamp.org/u/nameToReachPeople)\
**Post date:** [May 21, 2016, 5:23pm UTC](https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826/1 "2016-05-21T17:23:49Z")

</div>

I bump into this challange: [https://www.freecodecamp.com/challenges/falsy-bouncer](https://www.freecodecamp.com/challenges/falsy-bouncer)

By reading desc of task, u need to remove “falsy” boolean values. So i tried something like this:

EDIT: At the first moment, i link to challange with code, but think link is to large for showing whole code so here is:

```
function isFalsy(value){
  return (value !== false) && value !== null && value !== "" && value !== undefined && value !== 0 && typeof(value) !== NaN;
}

var haveString = true;

function bouncer(arr) {
  // Don't show a false ID to this bouncer
  console.log(arr);
  arr = arr.filter(isFalsy);
  console.log(arr);
  return arr.length === 0 ? []:arr;
}

bouncer([7, "ate", "", false, 9]);

```

And can’t figure out how on one side can have function that check if value is NotANumber and remove if so, and on other have String

Something like:

bouncer([7, “ate”, “”, false, 9]) should return [7, “ate”, 9]

bouncer([1, null, NaN, 2, undefined]) should return [1, 2]

But with this code works perfectly:

```
function isFalsy(value){
  return value;
}

function bouncer(arr) {
  // Don't show a false ID to this bouncer
  console.log(arr);
  arr = arr.filter(isFalsy);
  console.log(arr);
  return arr;
}

bouncer([7, "ate", "", false, 9]);
```

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [May 21, 2016, 5:27pm UTC](https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826/2 "2016-05-21T17:27:24Z")

</div>

Your code not only works, it’s the intended answer – except your `isFalsy` function really needs to be called `isTruthy` (or just `identity`) to accurately describe it.

The point of the challenge is to introduce the notion of “truthiness” and “falsiness” that are part of JavaScript, and that’s exactly what your algorithm captures.

---

<div class="post-metadata">

**Author:** ![nameToReachPeople](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nametoreachpeople/32/10814_2.png) [@nameToReachPeople](https://forum.freecodecamp.org/u/nameToReachPeople)\
**Post date:** [May 21, 2016, 5:47pm UTC](https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826/3 "2016-05-21T17:47:06Z")

</div>

I don’t look at challange as if it just introduce, that’s is subjective point of looking, i bump into this issue, i little search on google javascript boolean implementation but can’t find to compare this one and that.

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 3:46am UTC](https://forum.freecodecamp.org/t/how-to-implement-is-boolean-function-in-js/2826/4 "2021-01-16T03:46:43Z")

</div>

Closed on January 16, 2021, 3:46am UTC


