
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Converting strings to numbers with vanilla JavaScript
The parseInt function available in JavaScript has the following signature −
Syntax
parseInt(string, radix);
Where the parameters are the following −
string − The value to parse. If this argument is not a string, then it is converted to one using the ToString method. Leading whitespace in this argument is ignored.
radix − An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string.
So we can pass the string and the radix and convert any number with base from 2 to 36 to integer using this method. For example,
Example
console.log(parseInt("100", 10)) console.log(parseInt("10", 8)) console.log(parseInt("101", 2)) console.log(parseInt("2FF3", 16)) console.log(parseInt("ZZ", 36))
Output
This will give the output −
100 85 12275 1295
- Related Articles
- Converting Strings to Numbers in C/C++
- Converting strings to snake case in JavaScript
- Converting Strings to Numbers and Vice Versa in Java.
- Get div height with vanilla JavaScript
- JavaScript algorithm for converting Roman numbers to decimal numbers
- Converting numbers to Indian currency using JavaScript
- JavaScript algorithm for converting integers to roman numbers
- Converting numbers to base-7 representation in JavaScript
- Converting array of Numbers to cumulative sum array in JavaScript
- Converting numbers into corresponding alphabets and characters using JavaScript
- Implementing Heap Sort using vanilla JavaScript
- How to implement multiple input checkbox in vanilla JavaScript?
- What is the best way to learn Vanilla JavaScript?
- Converting all strings in list to integers in Python
- How to create a new object with only a subset of properties using vanilla Javascript

Advertisements