What is the difference between parseInt() and number()?

parseInt() and Number() are both used to convert a string into a number.

  • parseInt() parses the value of the string and converts to number till the first non-digit character.
  • Number() tries to convert the type of the string to number and returns nothing if there are non-digit characters in the string.


parseInt("67dpi");   // returns 67

// Convert type
Number('67dpi');     // returns NaN

Angular Posted Nov 07, 2020

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept