- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript parseInt and parseFloat
JavaScript Numbers & Math
JavaScript parseInt and parseFloat
parseIntandparseFloatread a number from the start of a string.
Unlike Number, they ignore whatever follows the number.
That is sometimes helpful and sometimes a trap.
Example
Example
javascript
console.log(parseInt("42px"));
console.log(Number("42px"));The output is 42 then NaN.
parseInt stopped at the first character it could not use.
How They Differ from Number
Number requires the whole string to be a number.
