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)
Answer from Nosredna on Stack Overflow
Top answer
1 of 5
3129

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 5
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript | MDN
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
Discussions

Convert a String to a Number in JavaScript
And I’m over here like +myString More on reddit.com
🌐 r/node
27
44
January 22, 2019
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
🌐
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).
🌐
Flavio Copes
flaviocopes.com › home › javascript › how to convert a string to a number in javascript
How to convert a string to a number in JavaScript
September 19, 2026 - Learn how to convert a string to a number in JavaScript using the Number object, parseInt() and parseFloat(), the unary plus, or multiplying by 1 for speed.
🌐
Coderwall
coderwall.com › p › 5tlhmw › converting-strings-to-number-in-javascript-pitfalls
Converting Strings to Number in Javascript: Pitfalls (Example)
September 27, 2024 - Result ~~~ .nvm/versions/node/v6.8.1/bin/node --require coffee-script/register src/liveserv-loader/test/benchmark.coffee b.hz 62781513.35543358 b.name parseInt b.hz 71269790.1318596 b.name Number(x) b.hz 22889466.345643885 b.name ~~convert b.hz 24447918.3306923 b.name convert|0 b.hz 78516405.25189222 b.name +convert Fastest is +convert ... Generally +<string> is fastest, but Number() occassionally comes out on top too. ... Good article! In the past, I often used "+" to coerce a character string to numeric form. I recently got tripped up by the fact that "+" is overloaded on concatenation in JavaScript, so instead of 1 + 2 = 3, I got 1 + 2 = 12!
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toString
Number.prototype.toString() - JavaScript | MDN
However, the BigInt constructor only has support for strings representing number literals (i.e., strings starting with 0b, 0o, 0x). In case your original radix is not one of binary, octal, decimal, or hexadecimal, you may need to hand-write your radix converter, or use a library.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-convert-string-to-number-js-string-to-int-example
JavaScript Convert String to Number – JS String to Int Example
November 7, 2024 - The is one of the fastest and easiest ways to convert something into a number. I said “something” because it converts far more than just string representations of numbers and floats – it also works on the non-string values true, false, and null or an empty string.
🌐
Joshtronic
joshtronic.com › 2024 › 07 › 28 › convert-string-to-number-with-javascript
Convert string to number with JavaScript - Joshtronic
July 28, 2024 - 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: ... If you were to pass in a number with a decimal, the function will still work, but it will strip everything after the decimal point. No rounding occurs either: ... This also works with integers, so this tends to be my preferred method to convert strings to numbers:
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
I prefer to use the Number() method because it’s easier for developers to read the code, and it’s quite intuitive to realize that it’s converting a string to Number. Performance chart rating each method to convert a javascript string to a number.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-a-number-to-a-string-in-javascript
Convert a Number to a String in JavaScript - GeeksforGeeks
September 8, 2026 - JavaScript provides several ways to convert an integer or floating-point number into a string.
🌐
Vultr Docs
docs.vultr.com › javascript › standard library › number › tostring()
JavaScript Number toString() - Convert to String
September 27, 2024 - In this article, you will learn how numbers are converted to strings and effectively employ the toString() method across various contexts. Enable JavaScript numbers to be transformed into strings easily and discover how to specify different ...
🌐
Reddit
reddit.com › r/node › convert a string to a number in javascript
r/node on Reddit: Convert a String to a Number in JavaScript
January 22, 2019 - As a side note, in more recent versions of JavaScript implementations parseInt now has a default radix of 10 no matter what is passed as the number. Still, passing it is considered the standard to ensure compatibility with older runtimes.
🌐
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 - In this article, I will show you 11 ways to convert a string into a number. One way to convert a string into a number would be to use the Number() function.
🌐
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 - Finally, the toString() method also accepts the radix or base parameter. The radix allows you to convert a number from the decimal number system (base 10) to a string representing the number in other number systems.
🌐
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 - Let’s explore some techniques available to use in JavaScript. Technique#1: Using Number() prebuilt function of JavaScript · The `Number()` function converts a string into a number.
🌐
DEV Community
dev.to › himanshudevgupta › 7-ways-to-convert-a-string-to-number-in-javascript-35pd
7 ways to convert a String to Number in JavaScript - DEV Community
February 21, 2023 - 3. Using Unary Operator (+) The unary plus operator (+) precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn't already. const x = 25; const y = -25; console.log(+x); // expected output: 25 console.log(+y); // expected output: -25 console.log(+''); // expected output: 0 · 4. Using parseFloat() parseFloat() parses a string and returns a number.
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › convert-string-to-integer-in-javascript
How to Convert String to Integer in JavaScript
August 5, 2025 - In JavaScript, you can convert a string to an integer using the following methods: let str = "123"; let num = parseInt(str); console.log(num); // 123 · let str = "123"; let num = +str; console.log(num); // 123 · let str = "123"; let num = Number(str); console.log(num); // 123 ·
🌐
YouTube
youtube.com › ghost together
JavaScript Convert String To Number (js) - YouTube
Sign Up 👻👻👉 https://semicolon.dev/YouTube(We're free online community, meet other makers!)#javascript #js #tutorial How to convert a string to a numberNu...
Published: June 2, 2022
🌐
DigitalOcean
digitalocean.com › community › questions › how-to-convert-a-string-to-an-integer-in-javascript
How to convert a string to an integer in JavaScript? | DigitalOcean
September 16, 2021 - Hi all, I wanted to create this question/answer on how to convert a string to an integer in JavaScript as this is something that I often get asked a lot a…