Working through Falsy Bouncer

Tell us what’s happening:
I get it. This exercise couldn’t be this simple. The code I wrote runs through each iteration of the array and checks for a falsy value. But why is it not detecting NaN, undefined, and null as falsy?

If I compare them directly, IE if (null == false) it returns the correct response. But in this if statement it doesn’t detect null, undefined, or NaN as false.

Your code so far

function bouncer(arr) {
  var resultArr = []
  
    for (let n = 0; n < arr.length; n++)
    {
      if ( arr[n] == true)
      {
      resultArr.push(arr[n])
      console.log(resultArr)
      }
    }
  
  return resultArr;
}

bouncer(["a", "b", "c"]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Falsy Bouncer

Link to the challenge:

This weak comparison isn’t doing that you thing and isn’t even needed!

You shouldn’t use var - it is a legacy feature of Javascript.

Thanks. I looked at the exercise description and researched how to convert a value to boolean.

That information helped tremendously.

The great thing is that you don’t need to convert to a boolean at all.

That’s interesting… I’m curious.