NaN

Nan stands for "Not a Number". It's what is displayed when the answer isn't numeric. JavaScript has to have some way of telling you that it can't extract a numeric value from the string you've given. It can't return a number - zero for example - because that might have been the valid result of a conversion. Instead it returns the special value NaN.

Note that this isn't the three-letter string "NaN". It's a special value in JavaScript called NaN.

Testing for NaN

Because NaN has no value it can cause some problems when you're testing the value of a variable. JavaScript can't compare NaN with anything else because NaN doesn't have a value. All we can say is that it's "Not a Number". Whatever comparison you try you will get false as the answer.

The solution is to use the isNaN() function. This will return true if it's give the value NaN as a parameter.

Related Items

Search page for Alvechurch Data

Searching a web site with JavaScript

Read More

Site Map

Site map of the Alvechurch Data site

Read More

Javascript while loops

JavaScript do and while loops

Read More

Javascript for loops

Javascript for loops

Read More

Repetition in Javascript

JavaScript structures for repetition

Read More