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
🌐
W3Schools
w3schools.com › jsref › jsref_parseint.asp
W3Schools.com
cssText getPropertyPriority() ... years"); parseInt("He was 40"); Try it Yourself » · The parseInt method parses a value as a string and returns the first integer....
🌐
GitHub
github.com › orgs › community › discussions › 77107
How to convert string to int in js? · community · Discussion #77107
@Dejan-Teofilovic, the following methods can convert strings to integer in JavaScript: let a = parseInt("1000"); let b = parseFloat("100.123"); let c = Number("1000"); In future, you can consider using W3schools or other forms of documentations to search for answers related to programming questions - e.g. https://www.w3schools.com/jsref/jsref_parseint.asp ·
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
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 hexadecimal, and so on.) The radix argument is converted to a number. If it's unprovided, or if the value becomes 0, NaN or Infinity (undefined is coerced to NaN), JavaScript assumes the following: If the input string, with leading whitespace and possible +/- signs removed, begins with 0x or 0X (a zero, followed by lowercase or uppercase X), radix is assumed to be 16 and the rest of the string is parsed as a hexadecimal number.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-a-string-into-integer-in-javascript
How to convert a string into integer in JavaScript?
In this approach to convert string to integer in JavaScript, we have used Math.round method. It converts string to integer through type coercion and then rounds the integer to nearest integer value considering decimal 0.5 as critical point. Here is an example implementing Math.round method ...
🌐
Educative
educative.io › answers › how-to-convert-string-to-int-or-number-in-javascript
How to convert string to int or number in JavaScript
JavaScript provides several methods for converting strings to numbers, including parseInt(), parseFloat(), Number(), the unary + operator, multiplication by 1, and the double tilde (~~) operator · Each method has specific use cases, so ...
Find elsewhere
🌐
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
🌐
Flexiple
flexiple.com › javascript › string-to-number
How to Convert a String to a Number In JavaScript - Flexiple
To convert a string to a number in JavaScript using the bitwise NOT operator (~), use a double bitwise NOT operator. The bitwise NOT operator in JavaScript, when applied once, inverts the bits of its operand.
🌐
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 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 ...
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › convert-string-to-integer-in-javascript
How to Convert String to Integer in JavaScript
August 5, 2025 - Learn the correct way to convert string to integer in JavaScript using parseInt(), Number(), and unary operator.
🌐
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 - In this article, you will learn some of the built-in JavaScript methods available for converting strings to numbers, along with an introduction (or refresher!) to the basics of how strings and numbers work in JavaScript.
🌐
WsCube Tech
wscubetech.com › resources › javascript › programs › string-to-int
String to Int (Integer) Conversion in JavaScript (9 Programs)
January 20, 2026 - Learn 9 simple ways to convert a string to an integer in JavaScript with examples and output. A complete guide for beginners to master type conversion easily.
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
Number() can be used to convert JavaScript variables to numbers. We can also use it to convert the string into a number.
🌐
Vultr Docs
docs.vultr.com › javascript › global › parseInt
JavaScript parseInt() - Parse String to Integer | Vultr Docs
September 30, 2024 - Its ability to parse integers from both simple and complex string formats makes it a valuable tool in web development, data processing, and anywhere data type conversion is required. Through the examples discussed, you grasp not only the basic usage but also how to handle edge cases and utilize the radix parameter effectively.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › parseInt
Number.parseInt() - JavaScript | MDN
The Number.parseInt() static method parses a string argument and returns an integer of the specified radix or base.
🌐
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.
🌐
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 - If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others. ... For everyone looking for a quick answer, here is how you could convert a string to an integer in Javascript with parseInt():