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 its first argument to a string, parses 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, ...
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 ... More on digitalocean.com
🌐 digitalocean.com
1
September 16, 2021
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
Integer to id name for getElementById
for (let i = 0; i < 10; i++) { console.log('a' + i.toString()); } or for (let i = 0; i < 10; i++) { console.log(`a${i}`); } More on reddit.com
🌐 r/javascript
8
0
May 11, 2017
🌐
Better Programming
betterprogramming.pub › what-is-the-best-way-to-convert-a-string-to-a-number-in-javascript-67052a1706c6
The Best Way to Convert a String to a Number in JavaScript | by Andrew Koenig-Bautista | Better Programming
March 6, 2020 - The parse methods, as the name suggests, attempt to parse through a string piece-by-piece as they convert it, Number() attempts to convert the entire string argument into a number, all at once. const str = '123abc'; Number(str); // NaN (attempts to convert entire string, cannot) parseInt(s); // 123 (stops as soon as it hits `a`) Number() is the JavaScript Number constructor called as a function, which performs a type conversion.
🌐
freeCodeCamp
freecodecamp.org › news › string-to-number-in-javascript-convert-a-string-to-an-int-in-js
String to Number in JavaScript – Convert a String to an Int in JS
August 30, 2022 - You can check that for yourself by doing the following: ... The parseInt() function takes two arguments: a string as the first argument and a radix as the second optional 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.
🌐
Educative
educative.io › answers › how-to-convert-string-to-int-or-number-in-javascript
How to convert string to int or number in JavaScript
Use Number() or the unary + operator if you want to handle both integers and floats automatically. These methods are useful when you need to convert directly to a number regardless of the format of the input string.
🌐
Vultr Docs
docs.vultr.com › javascript › global › parseInt
JavaScript parseInt() - Parse String to Integer | Vultr Docs
September 30, 2024 - The parseInt() function in JavaScript is a fundamental utility used to convert strings into integers. This method proves invaluable when you need to extract numbers from text data, or when handling inputs that should be integers for mathematical ...
Find elsewhere
🌐
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.
🌐
OpenReplay
blog.openreplay.com › convert-string-integer-javascript
How to Convert a String to an Integer in JavaScript
February 9, 2025 - Converting a string to an integer in JavaScript is simple with parseInt(), Number(), or the unary + operator.
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_number.asp
JavaScript Number toString() Method
The toString() method is used by JavaScript when an object needs to be displayed as a text (like in HTML), or when an object needs to be used as a string.
🌐
GitHub
github.com › orgs › community › discussions › 77107
How to convert string to int in js? · community · Discussion #77107
November 27, 2023 - 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.
🌐
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 ·
🌐
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
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
May 13, 2024 - 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.
🌐
Flexiple
flexiple.com › javascript › string-to-number
How to Convert a String to a Number In JavaScript - Flexiple
June 6, 2024 - JavaScript provides several methods to achieve this conversion. The parseInt() function parses a string and returns an integer, while the parseFloat() function returns a floating-point number.
🌐
upGrad
upgrad.com › home › tutorials › software & tech › convert string to int in javascript
Convert String to int in JavaScript
February 3, 2025 - Let us learn how to convert string to int in javascript with different methods and why it is important to do so in this tutorial.
🌐
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 - 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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › parseInt
Number.parseInt() - JavaScript - MDN Web Docs
The Number.parseInt() static method parses a string argument and returns an integer of the specified radix or base. function roughScale(x, base) { const parsed = Number.parseInt(x, base); if (Number.isNaN(parsed)) { return 0; } return parsed * 100; } console.log(roughScale(" 0xF", 16)); // ...
🌐
Dead Simple Chat
deadsimplechat.com › blog › 5-ways-to-convert-string-to-a-number-in-javascript
5 Ways to Convert String to a Number in JavaScript
July 6, 2024 - parseInt() is useful when you want to parse a string and convert it into an integer. It is mmore useful when you want to convert strings with different bases such as binary, octal or hexadecimal · If you are looking for a JavaScript chat SDK to build chat messaging, you can consider DeadSimpleChat JavaScript SDK
🌐
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 - It may seem that the parseInt() method is the easiest one to use to convert a string to an integer in Javascript, but it’s always valuable to know how the other methods work and that there are multiple ways to solve a problem.