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 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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript - MDN Web Docs
The parseInt function converts ... that string, then returns an integer or NaN. If not NaN, the return value will be the integer that is the first argument taken as a number in the specified radix. (For example, a radix of 10 converts from a decimal number, 8 converts from octal, 16 from ...
Discussions

How to convert a string to an integer in JavaScript?
JavaScript has 7 data types, but the two most simple and common data types are strings and numbers. If we have a variable with the value '5', that is a string, but if our value is 5, then we have a number. Note that the string values have to be put in quotes. Let’s say that we want to add two integers together, for example... More on digitalocean.com
🌐 digitalocean.com
1
September 16, 2021
When you try adding a string to an integer in JavaScript and wait for an error but it returns a string instead
Memes! A way of describing cultural information being shared. An element of a culture or system of behavior that may be considered to be passed from one individual to another by nongenetic means, especially imitation · Create your account and connect with a world of communities More on reddit.com
🌐 r/memes
5
43
November 19, 2019
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
🌐
OpenReplay
blog.openreplay.com › convert-string-integer-javascript
How to Convert a String to an Integer in JavaScript
February 9, 2025 - The parseInt() function parses a string and returns an integer. It also allows specifying the number system (radix) for conversion. const str = ""42""; const number = parseInt(str, 10); console.log(number); // Output: 42 · The second argument, ...
🌐
W3Schools
w3schools.com › jsref › jsref_parseint.asp
JavaScript parseInt() Method
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10.
🌐
Vultr Docs
docs.vultr.com › javascript › global › parseInt
JavaScript parseInt() - Parse String to Integer | Vultr Docs
September 30, 2024 - Use parseInt() to convert the string to an integer. ... This code converts the string "123" into the integer 123. It's a straightforward example of how parseInt() interprets and converts string data.
🌐
Educative
educative.io › answers › how-to-convert-string-to-int-or-number-in-javascript
How to convert string to int or number in JavaScript
In JavaScript, the double tilde (~~) operator can be used to convert a string to a number, but this method will truncate any decimal portions if the input string contains a decimal value.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-a-string-into-integer-in-javascript
How to convert a string into integer in JavaScript?
January 7, 2020 - In this approach to convert string to integer in JavaScript, we have used Math.floor method. It converts string to integer through type coercion and then rounds the integer to nearest integer value. Here is an example implementing Math.floor method to convert string to integer.
Find elsewhere
🌐
Flexiple
flexiple.com › javascript › string-to-number
How to Convert a String to a Number In JavaScript - Flexiple
June 6, 2024 - This function parses a string argument and returns an integer of the specified radix or base. For instance, parseInt("123") returns the number 123. The syntax of parseInt() requires two parameters: the string to be converted and the radix.
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › convert-string-to-integer-in-javascript
How to Convert String to Integer in JavaScript
May 8, 2024 - If the string cannot be converted to a valid number (e.g., “abc”), parseInt(), +, and Number() will return NaN (Not-a-Number). You can handle this by checking isNaN(): let str = "abc"; let num = parseInt(str); if (isNaN(num)) { console.log("Not a valid number!"); } Work with our skilled Javascript developers to accelerate your project and boost its performance.
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
Below are several different methods you can use to convert a string into a number in JavaScript with example code. parseInt() parses a string and returns a whole number. Spaces are allowed. Only the first number is returned. This method has a limitation though. If you parse the decimal number, it will be rounded off to the nearest integer value and that value is converted to string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-a-string-to-an-integer-in-javascript
Convert a String to an Integer in JavaScript - GeeksforGeeks
July 11, 2025 - The number() method converts a string into an integer number. It works similarly to the unary plus operator.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-convert-string-to-number-js-string-to-int-example
JavaScript Convert String to Number – JS String to Int Example
August 5, 2025 - You can use the floor() method, which will round down the passed value to the nearest integer. The ceil() method, which is the opposite of floor(), rounds up to the nearest integer.
🌐
W3docs
w3docs.com › javascript
How to Convert String to Number in JavaScript
May 31, 2024 - Recommendation: If you change the number 1 into any other number, it will multiply the number of the string. If you put 0, the result will be 0. Note: If you add any text to the string, it will return NaN. The padStart() method is a built-in ...
🌐
Simplilearn
simplilearn.com › home › resources › software development › javascript tutorial: learn javascript from scratch › a guide to convert string to int in javascript
Convert String to an Int (Integer) in JavaScript | Simplilearn
September 16, 2025 - Learn how to convert string to an Int or Integer in JavaScript with correct syntax. Understand how to use the parseInt() method and find out examples for reference.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
freeCodeCamp
freecodecamp.org › news › how-to-convert-a-string-to-a-number-in-javascript
How to Convert a String to a Number in JavaScript
November 7, 2024 - Another method would be to subtract 0 from the string. Like before, JavaScript is converting our string value to a number and then performing that mathematical operation. ... The bitwise NOT operator (~) will invert the bits of an operand and ...
🌐
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 - Well, luckily for us, JavaScript has a ton of built-in functions called methods. And one of those methods is called Number(). Next, let’s learn how to use it. The Number() method lets us convert the string into a number. It is a pretty handy method, but it doesn’t convert our string into an integer.
🌐
xjavascript
xjavascript.com › blog › how-to-convert-a-string-to-an-integer-in-javascript
How to Convert a String to an Integer in JavaScript: Best Methods & Examples — xjavascript.com
July 10, 2025 - Understanding String-to-Integer Conversion in JavaScript · Method 1: parseInt() – Extract Numbers from Strings
🌐
GitHub
github.com › orgs › community › discussions › 77107
How to convert string to int in js? · community · Discussion #77107
January 7, 2025 - javascript Copy code let str = "456"; let int1 = Number(str); // int1 will be 456 · let int2 = +str; // int2 will also be 456 These methods will attempt to convert the entire string to a number.
🌐
DEV Community
dev.to › sanchithasr › 7-ways-to-convert-a-string-to-number-in-javascript-4l
7 ways to convert a String to Number in JavaScript - DEV Community
November 27, 2023 - One might need to use parseFloat() method for literal conversion. myString = '129' console.log(parseInt(myString)) // expected result: 129 a = 12.22 console.log(parseInt(a)) // expected result: 12 · Number() can be used to convert JavaScript ...
🌐
Metana
metana.io › metana: coding bootcamp | software, web3 & cyber › full-stack › how to convert a javascript string to a number - metana
How to Convert a JavaScript String to a Number - Metana
September 27, 2024 - The simplest way to convert a string to a number is by using the built-in Number() function. This method works for both integers and floating-point numbers. // Syntax Number(string); // Example let str = "123"; let num = Number(str); // Output: 123