Skip to main content Accessibility Feedback

Numbers

Basic math

JavaScript includes a handful of basic arithmetic operators:

Operator Action
+ Add
- Subtract
* Multiply
/ Divide
% Remainder
// Add
// logs 4
console.log(2 + 2);

// Subtract
// logs 3
console.log(4 - 1);

// Divide
// logs 2
console.log(4 / 2);

// Multiply
// logs 10
console.log(5 * 2);

// Remainder
// logs 1 (2 goes into 5 twice, with 1 left over)
console.log(5 % 2);

Works back to at least IE6.