๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_tostring_number.asp
JavaScript Number toString() Method
The toString() returns a number as a string. Every JavaScript object has a toString() method.
๐ŸŒ
Medium
medium.com โ€บ @a1guy โ€บ how-to-convert-strings-to-numbers-in-javascript-9733d6314fec
How to Convert Strings to Numbers in JavaScript | by Ali Aslam | Medium
March 16, 2025 - Technique#1: Using Number() prebuilt function of JavaScript ยท The `Number()` function converts a string into a number.
Discussions

How can I convert a string to an integer in JavaScript? - Stack Overflow
There are two main ways to convert a string to a number in JavaScript. One way is to parse it and the other way is to change its type to a Number. All of the tricks in the other answers (e.g., unary plus) involve implicitly coercing the type of the string to a number. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Converting Strings to Number in Javascript: The Pitfalls

Number is most readable, and does what you expect if you want decimal, handlng leading zeros. The article says it's slower than parseInt. boo fucking hoo. Is Number parsing perf really holding your app back?

More on reddit.com
๐ŸŒ r/javascript
14
27
May 10, 2015
The unary + operator is a shortcut to convert a string into a number ๐Ÿคฉ
Neat. Don't do this. More on reddit.com
๐ŸŒ r/webdev
282
999
March 31, 2018
Why do I got "Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. " it's make me misleading
TL;DR : It's because of the string|number. Ok how do we find the root cause of the issue, the first intuition could be the Enum things, let's simplify the exemple and get rid of the enum : function test(key: 'A' | 'B', value: number | string) { let data = {A: 1, B: "1"}; data[key] = value; // Type 'string' is not assignable to type 'never'. } No luck, it's not about the Enum keys :( What about the number | string, let's play with numbers only: function test(key: 'A' | 'B', value: number) { let data = {A: 1, B: 2}; data[key] = value; // it works. } It works ! So what is the problem ? If your IDE is smart enough, when you put your mouse on the data variable it should show its type, and it should be this : {A: number, B: string} ... But wait, I suppose it's not what you want, actually what you want ( I guess but not sure) is {A: string|number, B: string|number}. If it's the case you have to specify the data type because typescript is going too far in its type inference. let data: Record = {A: 1, B: '2'}; So, finally why does it fails ? Since TS assume that A is a number and B is a string and your value is string | number. So data['A'] = value fails because value needs to be number but is actually number|string. And the same things happens for the data['B'], meaning this assignement is never correct ... More on reddit.com
๐ŸŒ r/typescript
8
4
June 16, 2020
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ typescript โ€บ how-to-convert-number-to-string-in-typescript
How to Convert Number to String in TypeScript ? - GeeksforGeeks
August 5, 2025 - It can also be used to convert ... Constructor. ... Example: In this example, String(num) converts the number 123.78 into a string "123.78" using the String constructor....
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert string to number in javascript
String to Number Javascript | Scaler Topics
January 6, 2024 - A string in a Javascript program can be converted into a number using the parseFloat() function. The parseFloat function in Javascript takes a string and converts it into a decimal value.
๐ŸŒ
GitHub
gist.github.com โ€บ robdecker โ€บ 42e39d83c64bca1b2e5e44166a1d931b
7 ways to convert a String to Number in JavaScript.md ยท GitHub
One might need to use parseFloat() ... a = 12.22 console.log(parseInt(a)) // expected result: 12 ยท Number() can be used to convert JavaScript variables to numbers....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-number-to-string-how-to-use-tostring-to-convert-an-int-into-a-string
JavaScript Number to String โ€“ How to Use toString to Convert an Int into a String
March 22, 2021 - The toString() method is a built-in method of the JavaScript Number object that allows you to convert any number type value into its string type representation. How to Use the toString Method in JavaScript To use the toString() method, you simply ...
๐ŸŒ
Joshtronic
joshtronic.com โ€บ 2024 โ€บ 07 โ€บ 28 โ€บ convert-string-to-number-with-javascript
Convert string to number with JavaScript - Joshtronic
July 28, 2024 - There's also multiple ways to approach the problem, based on what type of number you're expecting to get back. If you are expecting a string to be an integer, you can use the parseInt function, explicitly letting it know the base you're working with:
๐ŸŒ
DEV Community
dev.to โ€บ kiani0x01 โ€บ how-to-convert-javascript-number-to-string-5dad
How to Convert JavaScript Number to String - DEV Community
July 6, 2025 - A quick and dirty way to convert a number is by adding an empty string + ''. JavaScript will coerce the number into a string, and you get your result in one short line.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ convert-a-string-to-number-in-javascript
Convert a String to Number in JavaScript - GeeksforGeeks
July 23, 2025 - The + operator can be operated with the string by using it before the name of the string variable to convert it into a number. ... Example: The below code implements the + operator to convert a string into a number.
๐ŸŒ
JSON
json.org
JSON
A character is represented as a single character string. A string is very much like a C or Java string. A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used. Whitespace can be inserted between any pair of tokens.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ javascript-convert-number-to-string
JavaScript Convert Number to String
March 11, 2019 - There are some built-in methods in JavaScript that provide conversion from an number data type to a String, which only differ in performance and readability.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_type_conversion.asp
JavaScript Type Conversions
The global method Number() converts a variable (or a value) into a number. A numeric string (like "3.14") converts to a number (like 3.14).
Top answer
1 of 16
3114

The simplest way would be to use the native Number function:

var x = Number("1000")

If that doesn't work for you, then there are the parseInt, unary plus, parseFloat with floor, and Math.round methods.

parseInt()

var x = parseInt("1000", 10); // You want to use radix 10
    // So you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])

Unary plus

If your string is already in the form of an integer:

var x = +"1000";

floor()

If your string is or might be a float and you want an integer:

var x = Math.floor("1000.01"); // floor() automatically converts string to number

Or, if you're going to be using Math.floor several times:

var floor = Math.floor;
var x = floor("1000.01");

parseFloat()

If you're the type who forgets to put the radix in when you call parseInt, you can use parseFloat and round it however you like. Here I use floor.

var floor = Math.floor;
var x = floor(parseFloat("1000.01"));

round()

Interestingly, Math.round (like Math.floor) will do a string to number conversion, so if you want the number rounded (or if you have an integer in the string), this is a great way, maybe my favorite:

var round = Math.round;
var x = round("1000"); // Equivalent to round("1000", 0)
2 of 16
306

Try parseInt function:

var number = parseInt("10");

But there is a problem. If you try to convert "010" using parseInt function, it detects as octal number, and will return number 8. So, you need to specify a radix (from 2 to 36). In this case base 10.

parseInt(string, radix)

Example:

var result = parseInt("010", 10) == 10; // Returns true

var result = parseInt("010") == 10; // Returns false

Note that parseInt ignores bad data after parsing anything valid.
This guid will parse as 51:

var result = parseInt('51e3daf6-b521-446a-9f5b-a1bb4d8bac36', 10) == 51; // Returns true
๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-convert-a-string-to-a-number-in-javascript
How to convert a string to a number in JavaScript ยท CoreUI
September 26, 2025 - Use Number() constructor or unary plus operator to convert strings to numbers efficiently in JavaScript.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-string-to-number-in-javascript
How to convert String to Number in JavaScript?
September 20, 2024 - It forces the type conversion where JavaScript internally checks for valid number i.e integers or floats then converts them into number by type coercion or automatic conversion. Here is an example implementing unary operator to convert string to number.
๐ŸŒ
Medium
habtesoft.medium.com โ€บ convert-a-string-to-a-number-in-javascript-73b7b32fc622
Convert a string to a number in JavaScript | by habtesoft | Medium
October 18, 2024 - Convert a string to a number in JavaScript The parseInt() function is used to parse a string and return an integer. It takes two arguments - the string to parse and the radix (which specifies the โ€ฆ
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number โ€บ toString
Number.prototype.toString() - JavaScript | MDN
Rather, the algorithm uses the least number of significant figures necessary to distinguish the output from adjacent number values. For example, if the number is large, there will be many equivalent string representations of the same floating point number, and toString() will choose the one with the most 0s to the right (for any given radix).
๐ŸŒ
DEV Community
dev.to โ€บ emnudge โ€บ converting-strings-to-numbers-in-js-subtleties-secrets-and-slip-ups-478k
Converting Strings To Numbers in JS: Subtleties, Secrets, and Slip-ups - DEV Community
August 12, 2019 - Passing it a string representation of a number, it will return an integer version. parseInt() can also be passed a second parameter - the radix. This number describes in which base to process the number.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-convert-a-string-to-a-number-in-javascript
How to Convert a String to a Number in JavaScript
May 2, 2022 - Another way to convert a string into a number is to use a basic math operation. You can multiply the string value by 1 and it will return a number. ... As you can see, when we multiply the quantity value by 1, then it returns the number 12. But how does this work? In this example, JavaScript is converting our string value to a number and then performing that mathematical operation.