Python Arithmetic, Math Object & Modulo
JavaScript supports arithmetic operators (+, -, *, /, %, **), compound assignments (+=, *=), and the built-in Math object for advanced operations like Math.round(), Math.floor(), Math.sqrt(), and Math.random().
"The Math object is like a pre-loaded scientific calculator bundled directly inside the JavaScript runtime."
Deep Dive: How It Works
Modulo (%): Returns the remainder of division (e.g., 10 % 3 = 1). Useful for checking even/odd numbers.
Exponentiation (**): 2 ** 3 = 8 (replaces Math.pow(2, 3)).
Rounding Methods: Math.floor() rounds down, Math.ceil() rounds up, Math.round() rounds to nearest integer.
Syntax Blueprint
Math.round(4.7) ──▶ 5 | 17 % 5 ──▶ 2 | 2 ** 8 ──▶ 256
Use arithmetic operators for basic calculations and the Math object for rounding and powers.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Floating-point precision in 0.1 + 0.2.Why it happens: Binary floating-point arithmetic causes 0.1 + 0.2 to evaluate to 0.30000000000000004.
How to fix: Use Math.round() or .toFixed(2) for financial and currency formatting.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Calculate circle area with Math.PI
Given const radius = 5;
Calculate area = Math.PI * (radius ** 2);
Round area to the nearest integer using Math.round(area).
Print "Rounded Area: 79".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.