1. The "Not-a-number" value is represented as NaN (upper-case N, lower-case a, upper-case N)
2. NaN should not be in quotes. "NaN" is interpreted not as the not-a-number value, but as a string containing three characters, N, a and N.
Your test should therefore be written:
This may not have the desired effect, however. If the value of numb is "ten" or "$20", then the test will work as expected because parseInt() will return NaN. However, consider the case where numb="15.8". The test will be equivalent to:
parseInt works like this: it looks at the first character and finds a digit, so, whatever else it does, it doesn't return NaN. The second character is also a digit. The third character, however, is not, so parseInt() takes the portion of the string to the left of the decimal point and converts it to a number: 15. This is the value it returns, so the test is now:
15 is not NaN, so the test resolves to false and the error message is not displayed even though the user did not type in an integer. The original value "15.8" is still stored in the variable numb. That's why I test the parsed value against the value typed in.
If, on the other hand, you don't mind accepting a decimal number and discarding the decimal portion, you'll need to assign the return value of parseInt() to numb and test that:
This will, however, always round down (e.g. 15.8 to 15). To round to the nearest integer (15.8 to 16), use Math.round():