By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Testing for NaN

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
> 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

P: n/a
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

P: n/a
> 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

P: n/a
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.