JavaScript Arithmetic Operator

Arithmetic operators perform mathematical operations on numbers and are used to perform simple arithmetic calculations. In this guide, we will explore the different types of JavaScript arithmetic operators, their use cases, and how they work.

NameOperatorExample
Addition+x + y
Subtraction-x - y
Multiplication*x * y
Division/x / y
Modulus%x % y
Exponentiation**x ** y
Increment++++x
Decrement----x

Addition Operator (+)

The addition operator is used to add two numbers together. It can also be used to concatenate two strings. If both operands are numbers, the operator will return the sum of the numbers. If one or both operands are strings, the operator will return the concatenated string.

Example:

1let x = 10; 2let y = 20; 3let z = x + y; // returns 30

Subtraction Operator (-)

The subtraction operator is used to subtract one number from another. It returns the difference of the two numbers.

Example:

1let x = 10; 2let y = 20; 3let z = y - x; // returns 10

Multiplication Operator (*)

The multiplication operator is used to multiply two numbers. It returns the product of the two numbers.

Example:

1let x = 10; 2let y = 20; 3let z = x * y; // returns 200

Division Operator (/)

The division operator is used to divide one number by another. It returns the quotient of the two numbers.

Example:

1let x = 10; 2let y = 20; 3let z = y / x; // returns 2

Modulo Operator (%)

The modulo operator is used to find the remainder of a division operation. It returns the remainder of dividing one number by another.

Example:

1let x = 10; 2let y = 20; 3let z = y % x; // returns 0

Exponentiation Operator (**)

The exponentiation operator is used to calculate the power of a number. It returns the first operand raised to the power of the second operand.

Example:

1let x = 2; 2let y = 3; 3let z = x ** y; // returns 8

Increment Operator (++)

The Increment operator is used to increment a number by 1.

Example:

1let x = 10; 2x++; // returns 11

Decrement Operator (--)

The Decrement operator is used to decrement a number by 1.

Example:

1let x = 10; 2x--; // returns 9