Arithmetic Operators0%
Arithmetic Operators
Beginner12 min read•Updated: Jul 11, 2026
Arithmetic Operators in JavaScript
Arithmetic operators allow programs to perform mathematical calculations on numerical operands. JavaScript provides all standard mathematical operations along with exponentiation, modulo division, and unary increment/decrement operators.
1. Core Arithmetic Operators
| Operator | Name | Example | Result | Description |
|---|---|---|---|---|
+ | Addition | 10 + 5 | 15 | Adds two numbers (also concatenates strings!) |
- | Subtraction | 20 - 8 | 12 | Subtracts right operand from left |
| *``** | Multiplication | 6 * 7 | 42 | Multiplies two numbers |
/ | Division | 20 / 4 | 5 | Divides left operand by right operand |
% | Modulus (Remainder) | 14 % 4 | 2 | Returns integer remainder of division |
| ``** | Exponentiation (ES6) | 2 ** 3 | 8 | Raises base to power of exponent ($2^3$) |
2. Modulus % vs. Math Power **
The Power of Modulus %:
The remainder operator is frequently used to determine even/odd status or cycle through array indices:
JavaScript
// Check if a number is even
const isEven = (num) => num % 2 === 0;
console.log(isEven(8)); // true
console.log(isEven(7)); // false
// Cycling through 7 days of the week:
let dayIndex = 10 % 7; // 3 (Wednesday)
Exponentiation **:
JavaScript
console.log(3 ** 2); // 9 (3 squared)
console.log(4 ** 0.5); // 2 (Square root of 4!)
3. Increment (++) and Decrement (--)
JavaScript supports both prefix and postfix increment and decrement:
JavaScript
let count = 5;
// Postfix (increments AFTER current expression evaluates):
let a = count++; // a is 5, count is now 6
// Prefix (increments BEFORE current expression evaluates):
let b = ++count; // count becomes 7, b is 7
Pro Tip
[!TIP]
In modern clean code, avoid burying
++ inside complex expressions. Write it on its own line:
```javascript
count++;
```4. The Addition Trap: String Concatenation (+)
The plus operator (+) is overloaded in JavaScript:
- If both operands are numbers, it performs mathematical addition.
- If either operand is a string, it performs string concatenation!
JavaScript
console.log(10 + 20); // 30 (Number addition)
console.log("10" + 20); // "1020" (String concatenation!)
console.log(10 + 20 + "5");// "305" (Left-to-right: 10+20=30, then 30 + "5" = "305")
console.log("5" + 10 + 20);// "51020" ("5"+10="510", then "510"+20="51020")
Type Conversion Tip: Unary Plus (+)
Prefixing any string containing numbers with + converts it directly into a number:
JavaScript
let strAge = "25";
let numAge = +strAge; // Exactly 25 (number)
console.log(typeof numAge); // "number"
Interactive Quiz
Practice Quiz
Question 1
What is the result of the expression
17 % 5 in JavaScript?Question 2
What does the expression
2 ** 4 evaluate to?Question 3
What is the result of
"10" + 5 in JavaScript?Question 4
If
let x = 3; let y = x++;, what are the values of x and y respectively?Question 5
How can you quickly convert the numeric string
"42" into the primitive number 42 using an arithmetic operator?Next Lesson
Comparison Operators
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Comments and Best Practices | Comparison Operators |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.