Search⌘ K

Using Operators

Explore how to use JavaScript operators to perform arithmetic calculations, assign and update values, and manipulate data. Understand the role of arithmetic, assignment, and unary operators for effective coding and how to apply best practices for cleaner, more readable scripts.

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:

JavaScript
let a = 10, b = 2;
let sum = a + b; // 12
let difference = a - b; // 8
let product = a * b; // 20
let quotient = a / b; // 5
let remainder = a % b; // 0
let exponent = a ** b; // 100
console.log(sum, difference, product, quotient, remainder, exponent);

In the above code:

  • Line 1: Variables a and b are initialized.

  • Line 2: The + operator adds a and b.

  • Line 3: The - operator subtracts b from a.

  • Line ...