JavaScript Arithmetic Operators
Arithmetic operators are used to perform basic mathematical calculations like addition, subtraction, multiplication, and more.
1. Addition (+)
Adds two numbers or combines strings.
Example (Numbers):
let a = 5;
let b = 3;
let sum = a + b;
console.log(sum); // 8
Example (Strings):
let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName;
console.log(fullName); // John Doe
2. Subtraction (-)
Subtracts one number from another.
let a = 10;
let b = 4;
console.log(a - b); // 6
3. Multiplication (*)
Multiplies two numbers.
let a = 6;
let b = 3;
console.log(a * b); // 18
4. Division (/)
Divides one number by another.
let a = 20;
let b = 4;
console.log(a / b); // 5
5. Modulus (%)
Gives the remainder of a division.
let a = 10;
let b = 3;
console.log(a % b); // 1
6. Exponentiation (**)
Raises a number to the power of another number.
let a = 2;
let b = 3;
console.log(a ** b); // 8
7. Increment (++)
Adds 1 to a variable.
let x = 5;
x++;
console.log(x); // 6
8. Decrement (--)
Subtracts 1 from a variable.
let x = 5;
x--;
console.log(x); // 4
Summary Table
Operator | Meaning | Example |
---|---|---|
+ | Addition | 5 + 3 |
- | Subtraction | 10 - 4 |
* | Multiplication | 5 * 2 |
/ | Division | 20 / 4 |
% | Modulus | 10 % 3 |
** | Exponentiation | 2 ** 3 |
++ | Increment | x++ |
-- | Decrement | x-- |