Javatpoint Logo
Javatpoint Logo

JavaScript Number parseInt() method

The 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.

Syntax

The parseInt() method is represented by the following syntax:

Parameter

string - 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.

Return

An integer number. It returns NaN, if the first character cannot be converted to a number.

JavaScript Number parseInt() method example

Here, we will understand parseInt() method through various examples.

Example 1

Let's see a simple example of parseInt() method.

Test it Now

Output:

50
50
NaN
50
50

Example 2

Let's see an example to add two strings with and without using parseInt() method.

Test it Now

Output:

Before invoking parseInt(): 1020
After invoking parseInt(): 30

Example 3

In this example, we will pass radix argument within parseInt() method.

Test it Now

Output:

50
40
80

Next TopicJavaScript Math





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA