HomeTutorsContact
JavaScript
How to convert a string to the Number type in JavaScript?
Gulshan Saini
June 25, 2020
1 min

A string or any other value can be converted into number using Number() constructor. If the value cannot be converted to a valid number, NaN is returned.

Let’s look at couple of examples below

Number() constructor

Why not use parseInt()?

You must be thinking why I didn’t mention parseInt(). The limitation with parseInt is

  • It works only on strings. If the input is not string, it gets first converted to string.
  • parseInt() parse only initial characters till it hit a character it cannot convert

Tags

#javascript
Previous Article
How to insert an element before another using JavaScript?

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to Get Current Date in Human Readable Form in JavaScript?
October 03, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media