Parsing Numbers
parseInt and parseFloat read numbers from the start of a string. Number() is strict and returns NaN for bad input. isNaN and Number.isFinite check results.
Example
console.log(parseInt("42px"), parseFloat("3.14abc"), Number("42px"), Number(" 7 "));
console.log(Number.isNaN(NaN), Number.isFinite(10), Number.isInteger(5.0));Exercise
Strict conversion.
("12")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.