by @saigowthamr

How to convert string to number in JavaScript

Home » javascript » How to convert string to number in JavaScript

To convert a string to a number we need to 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.

const string = "4";

console.log(Number(string)); // 4