JavaScript parseint function| Convert a string to an integer Example

The javaScript parseint() method is to Convert a string to an integer (Number). The parseInt() is an inbuilt function in JavaScript, it accepts the string, radix parameter and converts it into an integer. If the given string doesn’t contain numbers, it returns Nan( not a number)

Syntax

Parameter Values

  • string: A given value want to parse to int.
  • radix: Its and Optional. An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string.

Return value

An integer parsed from the given string.

Examples of JavaScript parseint() function

Let’s see the example with different type of input.

Parse different strings:

Output:

JavaScript parseint function

Parseint negative number javascript

Q: How to convert a string into an integer in JavaScript?

Answer: You can converts string and into an integer using a parseInt() function.

Read more examples and methods:-

Do comment if you have any doubts and suggestions on this tutorial.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.