Work With Numbers in JavaScript II
JavaScript·2 min read·Jan 1, 2026
In JavaScript, beyond numeric data, the Number type is also used to represent special values like NaN, Infinity, or -Infinity.
Convert expressions to numbers
To convert a string or an expression into an integer or a floating point number, you can use the global built-in Number function:
Number(expression)Note that if the value can't be converted into a valid number, the Number function will return NaN.
Example
In this example, all values will be converted to numbers:
Number(1) // 1Number('123') // 123Number(null) // 0Number(true) // 1Number(false) // 0However, these values will be converted to NaN:
Number('text') // NaNNumber(undefined) // NaNConvert strings to integers
Unlock the program 🚀
Pay once, own it forever.
€79
30-day money-back guarantee
- 13 modules
- 113 lessons with full-code examples
- 29 projects with commented solutions
- All future lesson and project updates
- Lifetime access
By submitting this form, you agree to the Terms & Conditions and Privacy Policy.