Why does the NaN gets printed in the console?

Tell us what’s happening:

Your code so far


function bouncer(arr) {
  let emparr = [];
  // Don't show a false ID to this bouncer.
  for (let i=0; i<arr.length; i++){
    switch(arr[i]){
      case false:
      case null:
      case 0:
      case "":
      case NaN:
      case undefined: 
      continue;

      default:
      emparr.push(arr[i]);
    }
  }
  return emparr;
}

console.log(bouncer([1, null, NaN, 2, undefined]));

Because NaN !== NaN

1 Like

NaN === NaN is false

You need to find a different way to solve this. Consider this, these are all falsy values so with these value == false is true (note the not-strict equality operator)

1 Like

.filter() removes any value that is false.
All your case statements evaluate to false.
So just return the value inside a .filter() method.

1 Like