How to convert string of any base to an integer in JavaScript ? Last Updated : 12 Jan, 2022 Comments Improve Suggest changes Like Article Like Report Given a string containing an integer value and along with that user passes a base value. We need to convert that string of any base value to an integer in JavaScript. String Integer "1002" 1002 For performing the above-illustrated task, we would be using a method (or a function) provided by JavaScript called as parseInt(). This is a special method, provided by JavaScript, that takes an integer value (of any base which is either specified or not) and further converts the string into an integer value. Syntax: Following is the syntax that a user may use to convert a string into an integer value (of any base)- parseInt(string_value, base) Alternatively, if we don't want to specify the base value and just want to convert our string value into an integer value itself, then we may use the following syntax also- parseInt(string_value) Default value returned by base or radix of parseInt() method is 10. In other words, if we don't specify any base or radix value then it by default converts the string value to an integer value by taking into regard the base or radix value as 10. Let us visualize all of the above-illustrated facts with some of the following examples- Example 1: In this example, we would be passing the string value in a method (which is explicitly declared for ease purpose) and further that string value is passed inside the parseInt() method which then further converts that string value in the corresponding integer value. JavaScript <script> let stringConversion = (string_value) => { console.log("Initial Type: " + typeof string_value); let integer_value = parseInt(string_value); console.log("Final Type: " + typeof integer_value); console.log(integer_value); }; stringConversion("512000"); stringConversion("126410"); stringConversion("0x8975"); </script> Output: Initial Type: string Final Type: number 512000 Initial Type: string Final Type: number 126410 Initial Type: string Final Type: number 35189 Example 2: In this example, we would be passing the base value explicitly inside the method which is then further taken by the parseInt() method and further converts the string value into the corresponding integer value by taking into account the specified base value also. JavaScript <script> let StringConversion = (string_value, base) => { console.log( "String value is : " + string_value + " and base value is: " + base ); let Integer_value = parseInt(string_value, base); console.log("Integer value is: " + Integer_value); }; StringConversion("1011", 2); StringConversion("101", 10); StringConversion("10002", 8); </script> Output: String value is : 1011 and base value is: 2 Integer value is: 11 String value is : 101 and base value is: 10 Integer value is: 101 String value is : 10002 and base value is: 8 Integer value is: 4098 Comment More infoAdvertise with us Next Article How to convert string of any base to an integer in JavaScript ? amansingla Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Convert a String to an Integer in JavaScript These are the following ways to convert string to an integer in JavaScript:1. Using Number() MethodThe number() method converts a string into an integer number. It works similarly to the unary plus operator. JavaScriptlet s = "100.45"; console.log(typeof Number(s));Outputnumber 2. Using Unary + Oper 2 min read How To Convert Base64 to JSON String in JavaScript? There could be situations in web applications, where there is a need to decode the data from Base64 format back into its original JSON format. It generally happens when one has to transmit data over the network where Base64 encoding is well suited for encoding binary data.In this article, we will se 2 min read How to convert Integer array to String array using JavaScript ? The task is to convert an integer array to a string array in JavaScript. Here are a few of the most used techniques discussed with the help of JavaScript. Approaches to convert Integer array to String array:Table of ContentApproach 1: using JavaScript array.map() and toString() methodsApproach 2: Us 2 min read How to convert array of strings to array of numbers in JavaScript ? Converting an array of strings to an array of numbers in JavaScript involves transforming each string element into a numerical value. This process ensures that string representations of numbers become usable for mathematical operations, improving data handling and computational accuracy in applicati 4 min read How to Convert JSON to base64 in JavaScript ? Base 64 is the encoding scheme that represents binary data in a printable ASCII format, commonly used for data serialization and transmission. Table of Content Using btoa functionUsing Manual ConversionUsing btoa functionIn this approach, we're using btoa to encode a UTF-8 string representation of a 2 min read How to convert image into base64 string using JavaScript ? In this article, we will convert an image into a base64 string using Javascript. The below approaches show the methods to convert an image into a base64 string using Javascript.ApproachHere we will create a gfg.js file which will include JavaScript code and one gfg.html file.Now we will put onchange 2 min read How to convert long number into abbreviated string in JavaScript ? We are given a long number and the task is to convert it to the abbreviated string(eg.. 1234 to 1.2k). Here 2 approaches are discussed with the help of JavaScript.Approaches to Convert Long Number to Abbreviated String:Table of ContentUsing JavaScript methodsUsing Custom functionUsing logarithmsUsin 6 min read How to Get the Length of a String in Bytes in JavaScript ? In JavaScript, determining the length of a string in characters is straightforward using the length property. However, in many cases, particularly when dealing with file sizes, network protocols, or database storage, you might need to know the length of a string in bytes. This is because characters 3 min read How to convert string into float in JavaScript? In this article, we will convert a string into a float in Javascript. We can convert a string into a float in JavaScript by using some methods which are described below: Methods to Concert String into Float:Table of Content Method 1: By using Type Conversion of JavaScriptMethod 2: By using parseFloa 6 min read Convert base64 String to ArrayBuffer In JavaScript A Base64 string represents binary data in an ASCII string format by translating it into a radix-64 representation. Often used to encode binary data in text-based formats like JSON or HTML, it needs to be converted back into its original binary format for further processing. An ArrayBuffer in JavaScr 2 min read Like