473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2033
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
0
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and...
4
by: Peter Rilling | last post by:
Does VS.NET 2005 Professional support integrated unit testing, or is that only with the team system?
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
58
by: nw | last post by:
Hi, I have been asked to teach a short course on testing in C++. Until now I have used my own testing classes (which from what I've seen seem similar to the boost unit testing classes)....
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.