Sometimes, we want to convert string to number in JavaScript.
In this article, we’ll look at how to convert string to number in JavaScript.
How to convert string to number in JavaScript?
To convert string to number in JavaScript, we use the Number
function.
For instance, we write
const str = "1";
const num = Number(str);
to call Number
with str
to return 1.
Conclusion
To convert string to number in JavaScript, we use the Number
function.