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.

Example:

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

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

Angular Posted Nov 07, 2020

Join the Newsletter

Subscribe to get our latest content by email.
    We won't send you spam. Unsubscribe at any time.
    We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept