Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if ((y=="") && (isNaN(parseInt(y))))

Status
Not open for further replies.

engcomp

Programmer
Jun 18, 1999
66
AU
Maybe everybody knows this, but I learned it the hard way: Javascript treats y=="" and y==0 as being the same.

I have a little program that solves nonlinear equations online, see:


The evaluation function returns "" if an equation cannot be evaluated for a given x, otherwise, it returns the result of the evaluation, which could be zero (0).

Lo and behold, when it returned 0, it triggered the (y=="") test, which stops the program and outputs a message.

I found that you must test:
if ((y=="") && (isNaN(parseInt(y))))

Hope this helps somebody. Regards, Helmt
 
Rather than use y=="" here, test for an empty/null string with y.length==0 to see if there's any input at all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top