Numbers

JavaScript uses a single number type for both integers and floating-point numbers (64-bit IEEE 754).

Arithmetic Operators

10 + 3   // 13  addition
10 - 3   // 7   subtraction
10 * 3   // 30  multiplication
10 / 3   // 3.333... division
10 % 3   // 1   modulo (remainder)
10 ** 2  // 100 exponentiation

Assignment Operators

let x = 10
x += 5   // x = 15
x -= 3   // x = 12
x *= 2   // x = 24
x /= 4   // x = 6
x++      // x = 7 (increment)
x--      // x = 6 (decrement)

Math Object

Math.round(4.7)    // 5
Math.floor(4.7)    // 4
Math.ceil(4.2)     // 5
Math.abs(-10)      // 10
Math.max(1, 5, 3)  // 5
Math.min(1, 5, 3)  // 1
Math.sqrt(16)      // 4
Math.PI            // 3.141592653589793
Math.random()      // random number 0–1

Number Formatting

(3.14159).toFixed(2)   // '3.14'
(1000000).toLocaleString() // '1,000,000'
parseInt('42px')       // 42
parseFloat('3.14abc')  // 3.14