When the user types a value in an edit box or selects a value from a text-based control, the value is considered a simple group of words and the browser may not be able to identify or categorize what exists in a text-based control. The parsetInt() function is used to analyze what is in a text-based control. Its syntax is:
When calling this function, you must provide the argument. The interpreter will examine it from left to right. If the value is a natural number, parseInt() returns that number. For example, if you call it as:
the function will return 124. If the whole value is not a (natural) number, the interpreter will consider the numbers from left to right. If the first character of the argument is not a recognizable digit, the function would return a value known as NaN (not a number). If the first character from left is a digit, the interpreter will continue examining the other characters. When it finds a character that cannot be considered a digit, it would stop. It would then convert to number the digits found on the left side of the first non-digit character. For example, if you call it as:
the function would return 216.
Next: Using Functions