Number()
Converts the value to a number.
Syntax
Number(value)
Description
Converts the text to a number. Returns NaN if it cannot be converted. Unlike parseInt: the entire text must be a number.
Returns
Number or NaN.
Example
Loading editor…
Expected output
50 7
When to use?
Ignore the input text.
Common mistakes
- ⚠️ Number("12x") → NaN (whereas parseInt gives 12).