like this:

var foo = 45;
var bar = '' + foo;

Actually, even though I typically do it like this for simple convenience, over 1,000s of iterations it appears for raw speed there is an advantage for .toString()

See Performance tests here (not by me, but found when I went to write my own): http://jsben.ch/#/ghQYR

Fastest based on the JSPerf test above: str = num.toString();

It should be noted that the difference in speed is not overly significant when you consider that it can do the conversion any way 1 Million times in 0.1 seconds.

Update: The speed seems to differ greatly by browser. In Chrome num + '' seems to be fastest based on this test http://jsben.ch/#/ghQYR

Update 2: Again based on my test above it should be noted that Firefox 20.0.1 executes the .toString() about 100 times slower than the '' + num sample.

Answer from scunliffe on Stack Overflow
🌐
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
March 6, 2020 - Clarity should be taken into consideration when making decisions about such shortcuts. Not everyone may be aware of this behavior, which could lead to confusion for someone reading your code, whereas parseInt() is clear and concise. In my opinion, generally speaking, you should use code that describes what it does instead of code that uses a side-effect of a non-operation · Another shortcut of sorts, if you know the string that you are seeking to convert is a number, you can multiply it by one to convert it:
🌐
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.
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toString
Number.prototype.toString() - JavaScript | MDN
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 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript | MDN
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, ...
🌐
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.
🌐
Favtutor
favtutor.com › articles › number-to-string-javascript
Convert Number to String in JavaScript (5 Easy Methods)
November 23, 2023 - In this example, we have used the toString() function to convert the number 9 to a string. We passed various radices and stored the obtained strings in different variables which are printed on the console.
Find elsewhere
🌐
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.
🌐
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. function roughScale(x, base) { const parsed = Number.parseInt(x, base); if (Number.isNaN(parsed)) { return 0; } return parsed * 100; } console.log(roughScale(" 0xF", 16)); // ...
🌐
upGrad
upgrad.com › home › tutorials › software & tech › convert string to int in javascript
Convert String to int in JavaScript
February 3, 2025 - As a bonus for sticking with me for so long in this tutorial, I will quickly take you through converting int back to string in case you need it for experimenting with Java Script string to int. Let us check out some JavaScript convert string to int examples.
🌐
W3Schools
w3schools.com › js › js_type_conversion.asp
JavaScript Type Conversions
Values in quotes indicate string values. Red values indicate values (some) programmers might not expect. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Data types
July 9, 2024 - For example, a variable can at one moment be a string and then store a number: // no error let message = "hello"; message = 123456; Programming languages that allow such things, such as JavaScript, are called “dynamically typed”, meaning that there exist data types, but variables are not bound to any of them. ... The number type represents both integer ...
🌐
GreatFrontEnd
greatfrontend.com › questions › quiz › how-do-you-convert-a-string-to-a-number-in-javascript
How do you convert a string to a number in JavaScript? | Quiz Interview Questions with Solutions
September 5, 2021 - The unary plus operator can be used to convert a string to a number. It is a shorthand method and works for both integers and floating-point numbers.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-a-string-into-a-integer-without-using-parseint-function-in-javascript
Convert a string into a integer without using parseInt() function in JavaScript ? - GeeksforGeeks
2 weeks ago - The Math.round() function in JavaScript is used to round a number to the nearest integer. This method can also be used to convert a numeric string to an integer by rounding it to the nearest integer value.
🌐
Oreate AI
oreateai.com › blog › mastering-string-to-integer-conversion-in-javascript › 190420612cc4bf7e5db5180dc08ff6e6
Mastering String to Integer Conversion in JavaScript - Oreate AI Blog
December 31, 2025 - This method works seamlessly for straightforward cases but returns NaN (Not-a-Number) if the conversion fails—like trying to convert non-numeric strings such as 'Hello'. Another popular approach involves using parseInt(), which specifically parses strings and extracts integers:
🌐
Medium
habtesoft.medium.com › convert-a-string-to-a-number-in-javascript-73b7b32fc622
Convert a string to a number in JavaScript | by habtesoft | Medium
October 18, 2024 - The parseInt() function is used to parse a string and return an integer. It takes two arguments - the string to parse and the radix (which…
🌐
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 = "123abc"; let int = parseInt(str); // int will be 123 Using the Number() constructor or unary plus operator (+): You can also convert a string to a number using the Number() constructor or the unary plus operator.