JS: Arithmetic Operators

By Xah Lee. Date: . Last updated: .

Basic arithmetic

// plus, add
console.log(3 + 4);
// 7

// minus, substraction
console.log(3 - 4);
// -1

// negation
console.log(-(-3));
// 3

// multiply
console.log(3 * 4);
// 12

// divide
console.log(3 / 4);
// 0.75

Mod (remainder)

console.log(7 % 2);
// 1

console.log(7.4 % 2);
// 1.4000000000000004

console.log(7 % 3.4);
// 0.20000000000000018

Ceiling, floor, round

Power (exponential)

// power
console.log(3 ** 2);
// 9
// the ** operator supports bigint
console.log(3n ** 2n);
// 9n

Root