Categories
JavaScript Answers

How to convert string to number in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *