How to convert string to a number in JavaScript
Learn, how to convert the string to a number in JavaScript with the help of examples
To convert a string to a number, we can use the unary operator plus +
in JavaScript.
Here is an example:
const string = "4";
console.log(+string); // 4
Similarly, we can also the Number()
method in JavaScript to convert a string to number.
const string = "4";
console.log(Number(string)); // 4
The Number()
method takes the string number as an argument and converts it to a number.
Additional resources
You can also checkout similar tutorials by reading the following: