parseInt()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax

parseInt(string, radix)

parseInt(string)

Description

The parseInt() method is used to convert a string to an integer. It can take string input with an optional radix input. The radix input represents the base of the number in the string.

Example

Listing 6.205 shows how parseInt() is used to parse a string. A few different examples are shown for different types of strings.

Listing 6.205 Example of the parseInt() Method
 <html> <body> <script language="JavaScript"> <!–– Hide // convert the "859" string to an integer document.write("The string 859 converted to an integer is: "); document.write(parseInt("859") + "<br>"); // converts a binary ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.