JavaScript Math & Numbers

Master mathematical operations and number manipulation in JavaScript

1
2
3
Numbers & Basic Operations

🔢 JavaScript Numbers

JavaScript has one number type for both integers (whole numbers) and floats (decimal numbers). All numbers are stored as 64-bit floating point values.

Integers: 5, 100, -17
Floats: 3.14, 0.5, -2.7

➕ Arithmetic Operators

+Addition
6 + 9 = 15
-Subtraction
20 - 15 = 5
*Multiplication
3 * 7 = 21
/Division
10 / 5 = 2

⚠️ String vs Number

Be careful! Numbers in quotes are strings and behave differently:

"74" + 3"743" (string concatenation)
74 + 377 (number addition)
Interactive Calculator

Calculation

10 + 5 =15

Try different operators and see the results update in real-time!

🔄 String to Number
As string:"74" + 3 = "743"
As number:Click Test to see result

💡 Use Number() to convert strings to numbers for mathematical operations.

🎲 Math Methods
Math.random() =0

Random number between 0 and 1

Pro Tips
💡Use parentheses () to control operation order
🎯The remainder operator % is great for cycling through values
Use Math.random() * max for random integers
🔢Always convert user input to numbers with Number()