Skip to content

arithmetic operators (+, -, *, /, %)

In JavaScript, the arithmetic operators (+, -, *, /, %) take two operands and return their sum, difference, product, quotient, or remainder. They work on both number and bigint values, and every one except + converts other operand types to numbers first.

Both operands have to end up as the same numeric type. Mixing a number with a bigint throws a TypeError, and neither operand is converted.

JavaScript Arithmetic Operators Syntax

Each arithmetic operator sits between its two operands:

Language: JavaScript Syntax
<left> + <right>
<left> - <right>
<left> * <right>
<left> / <right>
<left> % <right>

The five operators give these results for the operands 7 and 2:

Operator Name Example Result
+ Addition 7 + 2 9
- Subtraction 7 - 2 5
* Multiplication 7 * 2 14
/ Division 7 / 2 3.5
% Remainder 7 % 2 1

The *, /, and % operators have higher precedence than + and -.

How the JavaScript Addition Operator Handles Strings

The + operator first converts both operands to primitives. If either one is then a string, + converts the other to a string and concatenates them. Otherwise, it adds them as numbers or bigints.

Say a form field holds a quantity as the string "3". The other operators convert it to a number, but + joins it as text:

Language: JavaScript
> const quantity = "3";
undefined

> quantity - 1
2
> quantity * 2
6
> quantity + 1
'31'

> Number(quantity) + 1
4

Converting the input with Number() first restores addition. Because + groups from left to right, 1 + 2 + "px" gives "3px", while "px" + 1 + 2 gives "px12".

JavaScript Arithmetic Operators Examples

Say a carousel with five slides steps back once from slide 0. The % operator keeps the sign of the dividend, so the plain remainder is negative:

Language: JavaScript
> const slideCount = 5;
undefined

> (0 - 1) % slideCount
-1
> (((0 - 1) % slideCount) + slideCount) % slideCount
4

Adding the divisor and taking the remainder again gives a true modulo, which wraps to the last slide.

Say an invoice total is stored in cents as a bigint. Multiplying it by a plain number throws, while bigint operands work and / truncates toward zero:

Language: JavaScript
> const totalCents = 10000n;
undefined

> totalCents * 3
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
> totalCents * 3n
30000n
> totalCents / 3n
3333n

Converting one side with BigInt() or Number() makes the types match.

JavaScript Arithmetic Operators Gotchas

  • The % operator returns a remainder that takes the sign of the dividend, so -7 % 3 is -1. A modulo takes the sign of the divisor and would give 2.
  • Dividing a number by zero returns Infinity, -Infinity, or NaN, but dividing a bigint by 0n throws a RangeError.
  • Decimal fractions aren’t stored exactly, so 0.1 + 0.2 evaluates to 0.30000000000000004.

JavaScript Arithmetic Operators Use Cases

  • Computing totals, averages, and percentages from numeric data
  • Wrapping an index around a fixed length with %
  • Testing whether an integer is even or odd with % 2
  • Doing exact integer math on large values with bigint operands
  • Building strings from pieces with +
A developer pulls a Math.floor() lever on a counting machine with a coffee sack on its scale, a big dial, a % gauge and a toFixed(2) receipt printer.

Course

JavaScript Numbers for Pythonistas

Port a coffee roastery's batch planner from Python to JavaScript, and learn to divide, round, read numbers from text, and format them with JavaScript's one number type.

basics js py

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026