How can I check NaN?

Possible duplicate:
Comparing NaN Values ​​for Equality in Javascript

Can someone tell me why this is not working?

if(inbperr == NaN){ document.getElementById('inbclo').value = "N/A"; } else{ document.getElementById('inbclo').value = "%" + inbperr; } 

Instead of returning a percentage value or "N / A", as if I want it to return "% NaN".

+44
javascript if-statement nan
Jul 6 2018-12-12T00:
source share
2 answers

NaN unusual: they are not equal, not even themselves. You need to use isNaN(inbperr) to determine if the value is NaN or not.

+82
Jul 06 2018-12-12T00: 00Z
source share

NaN is not a number. One of the few toxic types of JavaScript. It can reduce the whole expression to NaN.

http://www.crockford.com/javascript/encyclopedia/

+1
Jul 6 2018-12-12T00: 00Z
source share



All Articles