0

What is the use of parseint() function

7th Feb 2017, 9:53 AM
Raihanath Bindh Latheef
Raihanath Bindh Latheef - avatar
3 Réponses
+ 4
Hello there. The `parseInt` function is a method that allows you to transform a value into an integer. The base of the integer can be specified as the second argument. Give it a string, and you get either a return value of `NaN` or a valid integer. Give it a float (decimal) and you get its integer value. For example, var number = parseInt('200px', 10); // return 200 The function parses the string and returns the best possible value. In this case, it is able to obtain a number from the string. The '10' there, tells the function to leave the integer in base 10. You can pass in 2, 8, 16 and other bases you know. Passing an argument of '-&*' will return 'not a number' (NaN) value.
7th Feb 2017, 10:26 AM
John
John - avatar
+ 3
The second argument is used to specify the base of the number you passed in. It will also determine what kind of result you get. '10, 8' returns 8 while '10, 10' returns 10.
7th Feb 2017, 10:41 AM
John
John - avatar
0
thanks a lot
7th Feb 2017, 12:27 PM
Raihanath Bindh Latheef
Raihanath Bindh Latheef - avatar