-1

Duplicate question, removed for future people

D. Cantatore
  • 177
  • 11

3 Answers3

0

I don't think so, since as far as I know nothing is equal to NaN. However, you can take advantage of that and do:

if( * !== *){
      //code when * is NaN  
    };

And only a NaN will meet the condition. I read this is safer than just to use isNaN() .

Sergeon
  • 6,218
  • 1
  • 19
  • 41
0

You can do something like this

function convertIfNaN (x) {
    if (isNaN(x))
        return 0;
    else
        return x;
}
yitzih
  • 2,850
  • 3
  • 26
  • 42
0

You can use the isNaN function like so:

if (isNaN(x)) {
    // do something
}

The built in isNaN function will only check if the value can be coerced to a number. You can also write your own function to simply check for the value "NaN" like so:

function isNaN(x){
  return x !== x;
}
dalyhabit
  • 19
  • 4
  • I think this is the closest to what I was looking to achieve. It appears the simple clever code option doesn't really fit the situation and I just did a copy paste of a small if statement to check each time the variable would be used before it was used. Thanks! – D. Cantatore Aug 20 '16 at 19:28