Let’s look at three different ways to convert a string into a number.
parseInt() The parseInt() method converts a string into an integer (a whole number).It accepts two arguments. The first argument is the string to convert. The second argument is called the radix. This is the base number used in mathematical systems. For our use, it should always be 10.
parseFloat() The parseFloat() method converts a string into a point number (a number with decimal points). You can even pass in strings with random text in them.
Number() # The Number() method converts a string to a number.
Sometimes it’s an integer. Other times it’s a point number. And if you pass in a string with random text in it, you’ll get NaN, an acronym for “Not a Number.”
As a result of this inconsistency, it’s a less safe choice than parseInt() and parseFloat(). If you know the format of the number you’d like, use those instead. If you want the string to fail with NaN if it has other characters in it, Number() may actually be a better choice.