parseInt() / parseFloat()
Converts text to a number.
Syntax
parseInt(text) · parseFloat(text)
Description
parseInt reads the integer at the beginning of the text, parseFloat reads the decimal. Returns NaN if it finds no number.
Returns
Number or NaN.
Example
Loading editor…
Expected output
42 3.5
When to use?
Converting form/input text to a number.
Common mistakes
- ⚠️ parseInt("abc") → NaN; check the result before using it.