JavaScript | js intval
BelowistheexampleoftheparseInt()function.TheparseInt()functionisusedtoacceptthestring,radixparameterandconvertitintoaninteger.Theradixparameterisusedtospecifywhichnumeralsystemtobeused,forexample,aradixof16(hexadecimal)indicatesthatthenumberinthestringshouldbeparsedfromahexadecimalnumbertoadecimalnumber.IfthestringdoesnotcontainanumericvaluethenitreturnsNaNi.e,notanumber.Syntax:parseInt(Value,radix)Parameters:Thisfunctionacceptstwoparametersasmentionedaboveanddescribedbelow:Value:Thisparamet...
Below is the example of the parseInt() function.
The parseInt() function is used to accept the string ,radix parameter and convert it into an integer.The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number. If the string does not contain a numeric value then it returns NaN i.e, not a number.
Syntax:
parseInt(Value, radix)Parameters: This function accepts two parameters as mentioned above and described below:
Value: This parameter contains a string which is converted to an integer. radix: This parameter represents the radix or base to be used and it is optional.Return value: It returns a number and if the first character can’t be converted to a number then the function returns NaN. It actually returns a number parsed up to that point where it encounters a character that is not a number in the ...