DEV Community

Raj Maharjan
Raj Maharjan

Posted on

Convert string to number

parseInt

Because:

  1. parseInt(n) as name suggests, parses and doesn't simply convert.

Caveats:

  1. For later two, the string should only represent a number otherwise it will return NaN.
  2. However, parseInt("10 apples") can still parse string that starts with a number.

Top comments (0)