470,604 Members | 2,343 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

Testing for NaN

Hi All!

I know I can test like this:
if (isNaN("blah"))

But when I try this it doesn't work:
if ("blah" == Number.NaN)

What am I doing wrong?

Thanks for any advice!

Rob
:)
:>
:]
Jul 20 '05 #1
4 1989
> I know I can test like this:
if (isNaN("blah"))

But when I try this it doesn't work:
if ("blah" == Number.NaN)
Correction. I meant to say:
if (parseInt ("blah") == Number.NaN)
What am I doing wrong?

Thanks for any advice!


Rob
:)
:>
:]
Jul 20 '05 #2
Hi,

Robert Mark Bram wrote:
I know I can test like this:
if (isNaN("blah"))

But when I try this it doesn't work:
if ("blah" == Number.NaN)

Correction. I meant to say:
if (parseInt ("blah") == Number.NaN)
What am I doing wrong?

Thanks for any advice!

Rob


You didn't read the doc:

<quote>
NaN is always unequal to any other number, including NaN itself; you
cannot check for the not-a-number value by comparing to Number.NaN. Use
the isNaN function instead.
</quote>

From:
<URL:
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/number.html#1193302>

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #3
> You didn't read the doc:

<quote>
NaN is always unequal to any other number, including NaN itself; you
cannot check for the not-a-number value by comparing to Number.NaN. Use
the isNaN function instead.
</quote>


Oh. So much for that then. Thank you very much for pointing it out Laurent!

Rob
:)
:>
:]
Jul 20 '05 #4
JRS: In article <op*****************@news.optusnet.com.au>, seen in
news:comp.lang.javascript, Robert Mark Bram <re********@remove.this.optu
snet.com.au> posted at Thu, 1 Jan 2004 17:04:00 :-
I know I can test like this:
if (isNaN("blah"))

But when I try this it doesn't work:
if ("blah" == Number.NaN)

What am I doing wrong?


Using the second method instead of the first. Deciding that you know
what the second should do without reference to adequate documentation.
A NaN is not equal to anything at all, not even to another NaN generated
the same way, or to a copy of itself.
One use of this, BTW, is in dealing with a user-given range. If the
test is carefully arranged, it can give the desired result with NaN :

if (!(Y2-Y1<26) || Y1>Y2) { // does NaN
DynWrite(Div, "<b>Bad Range<\/b>") ; return }

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hugh Cowan | last post: by
reply views Thread by Jonathan Allen | last post: by
reply views Thread by Brian Russell | last post: by
4 posts views Thread by Peter Rilling | last post: by
72 posts views Thread by Jacob | last post: by
58 posts views Thread by nw | last post: by
reply views Thread by Matthew Fitzgibbons | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.