Syntax
a + b, a - b, a * b, a / b, a % b, a ** bExamples
Basic Arithmetic
The core arithmetic operators in action.
console.log(10 + 5); // 15
console.log(10 - 5); // 5
console.log(10 * 5); // 50
console.log(10 / 5); // 2
console.log(10 % 3); // 1 (remainder)
console.log(2 ** 3); // 8 (2 to the power of 3)Increment, Decrement, and String Concatenation
Common gotchas with + and the increment/decrement operators.
let count = 5;
count++; // count is now 6
count--; // count is now 5 again
console.log(1 + 1); // 2 (numeric addition)
console.log("1" + 1); // "11" (string concatenation)
console.log("5" - 1); // 4 (- forces numeric conversion)Best practices
- Be careful with + when mixing strings and numbers - it concatenates rather than adds if either side is a string
- Use Number() or parseInt()/parseFloat() to explicitly convert strings to numbers before arithmetic when the source is uncertain
- Prefer x += 1 or x++ consistently within a codebase for readability
- Watch for floating-point precision issues (e.g., 0.1 + 0.2 !== 0.3) when comparing decimal results directly
Runtime & versions
Browsers and JavaScript runtimes. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
ECMAScript specification