Skip to content

Operators and expressions

Arithmetic operators

Javascript provides several arithmetic operators that let you perform mathematical calculations.

SymbolNameDescription
+AdditionAdds two values
-SubtractionFinds the difference between two values
*MultiplicationMultiplies two values
/DivisionDivides one value by another
**ExponentiationRaises one value to the power of another
%RemainderCalculates the remainder on division

Expressions

An expression in javascript is a collection of operators and variables that evaluates down to a single value.

js
const bookPrice = 15 // variable
const numberOfBooks = 100 // variable
const totalValue = bookPrice * numberOfBooks // expression

console.log(totalValue)
console
1500

Modifying a variable

When updating a variable, we can use its old value to calculate its new value.

js
let availableBooks = 120
availableBooks = availableBooks + 10

console.log(availableBooks)
console
130

We can do this a bit more quickly with += and -=.

js
let availableBooks = 120

availableBooks += 10
console.log(availableBooks)

availableBooks -= 5
console.log(availableBooks)
console
130
125