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_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.
🌐
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

Does JavaScript supports conversion of integer X to X.0 as typeof number?
This doesn't really make sense in context of JavaScript. As far as JS is concerned, the numbers 5 and 5.0 are exactly the same. In context of JSON, the numbers are also exactly the same. Hence, you can't really "make 5 into 5.0" because it already is, and the fact the decimals are not displayed is just how the number happens to be formatted by the particular JS engine that's displaying it to you. If you have a bizarre API which refuses to accept numbers such as 5, but won't accept a string '5.0', you will probably have to format the values yourself. Eg. use whatever.toFixed(1), which gives you a string, and then manually strip out the string delimiters from the JSON data. You might be able to do this using the optional replacer function for JSON.stringify - just have it check if the value is typeof 'number', and ensure it always uses toFixed when formatting them. More on reddit.com
🌐 r/learnjavascript
41
21
January 1, 2023
Convert string to Integer in a JSON file
Array.map and Number More on reddit.com
🌐 r/learnjavascript
6
4
November 23, 2020
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
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 › Number › toString
Number.prototype.toString() - JavaScript - MDN - Mozilla
The toString() method of Number values returns a string representing this number value. function hexColor(c) { if (c < 256) { return Math.abs(c).toString(16); } return 0; } console.log(hexColor(233)); // Expected output: "e9" console.log(hexColor("11")); // Expected output: "b" ... An integer ...
🌐
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.
🌐
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 ·
Find elsewhere
🌐
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.
🌐
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.
🌐
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 ...
🌐
Flexiple
flexiple.com › javascript › string-to-number
How to Convert a String to a Number In JavaScript - Flexiple
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.
🌐
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.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-a-string-into-integer-in-javascript
How to convert a string into integer in JavaScript?
August 18, 2024 - In this approach to convert string to integer in JavaScript, we have used Math.trunc method. It returns the integer part of the number by truncating the decimal digits. Here is an example implementing Math.trunc method to convert string to integer.
🌐
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 › 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.
🌐
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 ...
🌐
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)); // ...
🌐
JavaScripter
javascripter.net › faq › convert2.htm
JavaScript string-to-number conversion
May 31, 2024 - Converting Strings to Numbers JavaScript FAQ | Numbers FAQ | Strings and RegExp FAQ · Question: How do I convert strings to numbers in JavaScript
🌐
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
April 24, 2024 - 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....