My code is working correctly but there is error

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function bouncer(arr) {

return  arr.filter(a=> a !== false && a !== "" && a !== null && a !== 0 && a !== undefined && a !== NaN );

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

  **Your browser information:**

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

Challenge: Falsy Bouncer

Link to the challenge:

It looks like you accidentally published your post before you were done. You should be able to edit it to tell us what is going on and how we can help.

This is not how you check for NaN.

How to Check for NaN in JavaScript

1 Like

should I use isNaN()?

anyway I figured it out with a better solution. thanks for help

I don’t think so. but thanks I got it out.

I know you solved this challenge using another method (which is probably a better solution than what you previously had) but just to clarify, you could solve it using your original attempt if you changed the way you were checking for NaN. If you looked at the article I linked to you would see that you needed to use Number.isNaN() for reasons they explain in the article.

Not sure if this is the solution you ended up with but as an FYI.

The filter method does the coercion for you and will only return truthy values. You can test this by simply returning the value inside the callback a => a

Checking for falsy and truthy values is one instance where using the language’s own implicit type coercion is often a lot better than explicitly checking for values.