Tuesday, May 12, 2009

NaN in Javascript and math constants

Javascript will return/alert the value as NaN (Not-a-Number) when a mathematical operation yields undefined result or an error.

For example, consider below sample code.
test1= "test1"/2;

Since dividing a string value with a numeric value is undefined, the division will return as "NaN". i-e alert(test1); will show "NaN".
We can not compare this "NaN" with any other number, so we need a special function for verifying it. isNaN() will be used for doing this test.

It will return "false" if the value is number, otherwise it will return "true" if it is not a number.

Properties of Math object can be used for getting math constants in javascript.

For example Math.PI will return value(3.14...) of PI.

More Articles...

No comments:

Thanks for visiting our blog

twitterrss facebook linkedin YouTube subscribe

Subscribe via email

Enter your email address: