Parsing Numbers
JS · Numbers & Mathsyntax
Number(value)
parseInt(string, radix)
parseFloat(string)example
console.log(Number("42")); // 42
console.log(Number("3.14abc")); // NaN
console.log(parseInt("3.14abc")); // 3
console.log(parseFloat("3.14abc")); // 3.14
console.log(parseInt("ff", 16)); // 255Note Number() is stricter -- rejects partially numeric strings. parseInt() stops at the first non-numeric character. Always pass the radix to parseInt() to avoid octal surprises.