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.

GroupBasic Types
KindType
Strict modeNot 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 / 1e5Decimal 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.
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().
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏