

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Converting strings to uppercase and lowercase with vanilla JavaScript
- 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
- Implementing Heap Sort using vanilla JavaScript
- Converting array of Numbers to cumulative sum array in JavaScript
- Converting numbers into corresponding alphabets and characters using JavaScript
- Converting all strings in list to integers in Python
- JavaScript - summing numbers from strings nested in array
- Why is vanilla ice cream white when vanilla extract is brown?
Advertisements