Can't Eliminate null Values - Falsy Bouncer

Can't Eliminate null Values - Falsy Bouncer
0.0 0


My below code works at removing all the values but null. Does anyone know why?

var falsey = [false, null, 0,"",undefined,NaN];

function remove(val){
  return falsey.indexOf(val) == -1;

function bouncer(arr) {
  var filtered = arr.filter(remove);
  return filtered;

bouncer([false, null, 0, NaN, undefined, ""]);


Did you mean it doesn’t remove the NaN?
Check this out:

null == null
NaN == NaN

It does not remove NaN because when the indexOf function does not find it in the array.

//logs -1

There is a function called isNaN that would return true in this case, more details here



You’re right! That was the issue. For some reason though, the console was returning the value to me as null not NaN. Any idea why?


I’m going to be DRY and just link to yesterday’s discussion: