Back to course

The Number Type: Integers and Floating Points

JavaScript: The Complete '0 to Hero' Beginner Course

12. The Number Type

In JavaScript, the Number type covers both whole numbers (integers) and numbers with decimal points (floats).

Integers

javascript let count = 42; let year = 2024;

Floating Point Numbers (Decimals)

javascript let price = 19.99; let piApproximation = 3.14159;

Arithmetic Operations

Numbers support standard math operations:

javascript let a = 10; let b = 3;

console.log(a + b); // Addition: 13 console.log(a - b); // Subtraction: 7 console.log(a * b); // Multiplication: 30 console.log(a / b); // Division: 3.333... console.log(a % b); // Modulo (Remainder): 1 console.log(a ** b); // Exponentiation: 1000

The Floating Point Problem

Due to how computers store numbers (binary floating-point standard), arithmetic with decimals can sometimes be imprecise (this is true for most programming languages).

javascript console.log(0.1 + 0.2); // Output: 0.30000000000000004 (NOT 0.3)

For financial applications, special libraries or working with cents (integers) is necessary.