Number: Floating-Point Only
What you'll learn: JavaScript represents all numbers — whole or decimal — as 64-bit floating-point values.
All Numbers Are the Same Type
In many programming languages, you distinguish between integers (whole numbers like 5) and decimals (like 5.5). JavaScript doesn't make that distinction internally. Whether you write 42, 3.14, or -0.001, JavaScript stores them all the same way: as 64-bit floating-point numbers (following the IEEE 754 standard).
Think of it like this: imagine a calculator that only has a decimal mode. Even when you type "10," it secretly thinks "10.0." That's JavaScript with numbers.
What This Means for You
console.log(5); // 5 (looks like an integer)
console.log(5.0); // 5 (same exact value)
console.log(0.1 + 0.2); // 0.30000000000004 (floating-point quirk!)
Because everything is floating-point:
- You can write
5or5.0— they're identical - JavaScript handles very large and very small numbers
- There can be tiny rounding errors with decimals (like
0.1 + 0.2not equaling exactly0.3)
You don't need multiple number types or special syntax. One Number type handles everything from -Infinity to Infinity.
Why Floating-Point?
This design choice keeps JavaScript simple for beginners — you don't worry about "int vs float." The tradeoff is that JavaScript isn't ideal for precision-critical math (like financial calculations) without extra care.
Key Takeaway: Every JavaScript number is a 64-bit floating-point value; there's no separate integer type, which keeps the language simple but introduces small precision quirks.