JavaScript Number parseInt() methodThe JavaScript number parseInt() method parses a string argument and converts it into an integer value. With string argument, we can also provide radix argument to specify the type of numeral system to be used. SyntaxThe parseInt() method is represented by the following syntax: Parameterstring - It represents the string to be parsed. radix - It is optional. An integer between 2 and 36 that represents the numeral system to be used. ReturnAn integer number. It returns NaN, if the first character cannot be converted to a number. JavaScript Number parseInt() method exampleHere, we will understand parseInt() method through various examples. Example 1Let's see a simple example of parseInt() method. Test it NowOutput: 50 50 NaN 50 50 Example 2Let's see an example to add two strings with and without using parseInt() method. Test it NowOutput: Before invoking parseInt(): 1020 After invoking parseInt(): 30 Example 3In this example, we will pass radix argument within parseInt() method. Test it NowOutput: 50 40 80 Next TopicJavaScript Math |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India