The parseint () function parses a string and returns an integer.
The parseint () method is used to convert a string to an integer.
Parseint (string, Radix): String required. All converted strings.
Radix option, 2 to 36, specifies the hexadecimal type of the string.
Code
< Script Type = " Text/JavaScript " >
Document. Write (parseint ( " 10 " )); // 10
Document. Write (parseint ( " 10.00 " )); // 10
Document. Write (parseint ( " 10.33 " )); // 10
Document. Write (parseint ( " 34 45 66 " )); // 34
Document. Write (parseint ( " 60 " )); // 60
Document. Write (parseint ( " 40 years " )); // 40
Document. Write (parseint ( " He was 40 " )); // Nan
Document. Write (parseint ( " 10 " )); // 10
Document. Write (parseint ( " 10 " , 10 )); // 10
Document. Write (parseint ( " 010 " )); // 8
Document. Write (parseint ( " 10 " , 8 )); // 8
Document. Write (parseint ( " 0x10 " )); // 16
Document. Write (parseint ( " 10 " , 16 )); // 16
< / SCRIPT>
After reading the above, you will certainly not understand Nan. Let's talk about Nan below.
Nan "not a number", this value is rare, so that we do not understand it. When the operation fails to return the correct value, the Nan value is returned. The Nan value is very special, because it is "not a number", so any number is not equal to it, or even Nan itself is not equal to Nan.
isnan calculates a parameter and checks whether it is a numerical value.
isnan (testvalue) returns true or false.
isnan is a built-in JavaScript function. It is not a method associated with any object, but a part of the language. On a platform that supports Nan, The parsefloat () and parseint () functions return "Nan" when calculating a value that is not a numerical value ". If the parameter passed by isnan () is "Nan", true is returned; otherwise, false is returned.