...

/

Arithmetic Operations

Arithmetic Operations

Learn about the arithmetic operation with examples.

Most programming languages can carry out all the usual arithmetic operations—just like a pocket calculator. Calculations can be set out as we would expect, and they often use the operators and symbols we’re familiar with. JavaScript is no exception. Let’s try doing some math in the below widget.

Addition

Addition uses the + operator, as we would expect:

Press + to interact
console.log(5 + 4.3);

This example shows that we can mix integers and floats in calculations.

Subtraction

Subtraction uses the - operator, and there are no problems dealing with negative numbers:

Press + to interact
console.log(6 - 11);

Multiplication

Multiplication uses the * operator:

Press + to interact
console.log(6 * 7);

Division

Division uses the / operator as if it was a fraction:

Press + to interact
console.log(3 / 7);

This answer should actually be a recurring decimal, but JavaScript will truncate the answer (usually with a slight rounding error at the end).

Exponentiation

Exponentiation can be carried out using the ** operator. The following code will return ...