number Number Type
Last updated: 2026-10-22
number Number Type
number covers both integers and decimals — JS has only one numeric type. Counts, prices, coordinates and timestamps are all number.
| Group | Basic Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
let count: number = 42;
let price = 19.99;
let hex = 0xff; // 255
⚙️ Parameters
| 0x / 0b / 0o / 1e5 | Decimal plus 0x hex, 0b binary, 0o octal and 1e5 scientific notation |
|---|
Returns:None — number is a basic type annotation and produces no runtime code.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
59.97
42 3.5
(Runtime output after transpilation; total is actually 59.970000000000005 — floating point multiplication has precision error)
💡 Notes
ℹ️ Info JS has no int/float split — every number is an IEEE-754 double, which is why 0.1 + 0.2 !== 0.3.
⚠️ Note Do not accumulate money in floats: use integer cents or a decimal library, and toFixed only for display.
💡 Tip parseInt/parseFloat parse unit strings ("42px", "3.5rem") nicely; they return NaN on failure — check with Number.isNaN.
🏷️ Related Basic Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Why is 0.1 + 0.2 !== 0.3?
A Binary floats cannot represent 0.1 and 0.2 exactly; the sum is 0.30000000000000004. Compare with an epsilon, or use integers/a decimal library.
Q Is there an upper limit for number?
A Safe integers go up to ±(2^53 - 1) = ±9007199254740991. Beyond that precision is lost — use bigint for larger exact integers.
Q Is NaN a number?
A Yes — typeof NaN === "number". You cannot test it with === (NaN equals nothing); use Number.isNaN().