Using Operators
Learn about JavaScript operators used to perform operations on variables and values.
We'll cover the following...
Operators are fundamental to performing actions on data in JavaScript. We use them to manipulate values, combine expressions, or perform arithmetic.
Arithmetic operators
Arithmetic operators perform mathematical calculations. These are as follows:
Operator | Description |
| Addition |
| Subtraction |
| Multiplication |
| Division |
| Modulus (Remainder) |
| Exponentiation |
Consider the following examples of using arithmetic operators in code:
Press + to interact
let a = 10, b = 2;let sum = a + b; // 12let difference = a - b; // 8let product = a * b; // 20let quotient = a / b; // 5let remainder = a % b; // 0let exponent = a ** b; // 100console.log(sum, difference, product, quotient, remainder, exponent);
In the above code:
Line 1: Variables
a
andb
are initialized.Line 2: The
+
operator addsa
andb
.Line 3: The
-
operator subtractsb
froma
.Line ...
Access this course and 1400+ top-rated courses and projects.