JavaScript Arithmetic Operators

Arithmetic operators are used in JavaScript to perform mathematical operations on numerical values. Here are some of the most commonly used arithmetic operators:

Addition (+)

The addition operator (+) is used to add two numbers together.

Example:

1let result = 5 + 3; // result is now 8

Subtraction (-)

The subtraction operator (-) is used to subtract one number from another.

Example:

1let result = 10 - 4; // result is now 6

Multiplication (*)

The multiplication operator (*) is used to multiply two numbers.

Example:

1let result = 6 * 7; // result is now 42

Division (/)

The division operator (/) is used to divide one number by another.

Example:

1let result = 20 / 4; // result is now 5
2let result2 = 22 / 4; // result2 is now 5.5

Modulus (%)

The modulus operator (%) returns the remainder of the division of one number by another.

Example:

1let remainder = 10 % 3; // remainder is 1

Increment (++) and Decrement (--)

The increment operator (++) adds 1 to a variable, and the decrement operator (--) subtracts 1 from a variable.

Example:

1let count = 5;
2count++; // count is now 6
3count--; // count is now 5