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.
| 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$) |
% vs. Math Power **%:The remainder operator is frequently used to determine even/odd status or cycle through array indices:
**:++) and Decrement (--)JavaScript supports both prefix and postfix increment and decrement:
++ inside complex expressions. Write it on its own line:
```javascript
count++;
```+)The plus operator (+) is overloaded in JavaScript:
+)Prefixing any string containing numbers with + converts it directly into a number:
17 % 5 in JavaScript?2 ** 4 evaluate to?"10" + 5 in JavaScript?let x = 3; let y = x++;, what are the values of x and y respectively?"42" into the primitive number 42 using an arithmetic operator?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Comments and Best Practices | Comparison Operators |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.