Language: EN

javascript-operadores-aritmeticos

Arithmetic Operators in Javascript

Arithmetic operators allow us to perform mathematical calculations such as adding, subtracting, multiplying, and dividing numerical values.

The basic arithmetic operators are:

OperatorNameDescription
+AdditionAdds two values
-SubtractionSubtracts the second value from the first
*MultiplicationMultiplies two values
/DivisionDivides the first value by the second
%ModulusReturns the remainder of the division of the first value by the second
**ExponentiationRaises the first value to the power of the second
++IncrementIncreases the value of a variable by one
--DecrementDecreases the value of a variable by one

If you want to learn more about Arithmetic Operators
check out the Introduction to Programming Course read more

List of arithmetic operators

Addition (+)

The addition operator is used to add two values.

let result = 10 + 5; // result is 15

Subtraction (-)

The subtraction operator is used to subtract one value from another.

let result = 10 - 5; // result is 5

Multiplication (*)

The multiplication operator is used to multiply two values.

let result = 10 * 5; // result is 50

Division (/)

The division operator is used to divide one value by another.

let result = 10 / 5; // result is 2

Exponentiation (**)

The exponentiation operator raises the first operand to the power of the second operand. It is useful for more advanced mathematical calculations and operations involving powers.

let result = 2 ** 3; // result is 8, i.e. 2 raised to the power of 3

Modulus (%)

The modulus operator returns the remainder of a division.

let result = 10 % 3; // result is 1, because 10 divided by 3 is 3 with a remainder of 1

Increment (++)

The increment operator increases the value of a variable by 1.

let number = 5;
number++; // Now number is 6

Decrement (—)

The decrement operator decreases the value of a variable by 1.

let number = 5;
number--; // Now number is 4