0
What is the use of parseint() function
3 Respostas
+ 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.
+ 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.
0
thanks a lot