JavaScript operators are special symbols that tell JavaScript to perform an action on values and variables. They are used to calculate numbers, assign values, compare data, join text, and make logical decisions inside a program.
Without operators, JavaScript could store values but would not be very useful in real programs. Operators let you build expressions such as adding prices, comparing ages, updating counters, or checking whether two values are equal.
In simple terms, operators are the working tools that help JavaScript do something with the data you write.
Here is a basic example that uses the assignment operator = and the
addition operator +:
let x = 5;
let y = 6;
let total = x + y;
console.log(total);
In this example:
= assigns values to variables+ adds x and yJavaScript has many operators, but beginners usually start with these main groups:
| Operator Type | Purpose | Examples |
|---|---|---|
| Arithmetic | Perform math calculations | +, -, *, /, % |
| Assignment | Assign values to variables | =, +=, -= |
| Comparison | Compare two values | ==, ===, >, < |
| Logical | Combine or reverse conditions | &&, ||, ! |
| String | Join text values | +, += |
Arithmetic operators are used for mathematical work such as addition, subtraction, multiplication, and division.
let a = 10;
let b = 4;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
These operators are commonly used in totals, prices, scores, percentages, and counters.
Assignment operators store values inside variables. The basic assignment operator is
=, but JavaScript also supports shortcut assignment operators.
let points = 10;
points += 5;
points -= 2;
console.log(points);
Here, += adds and assigns in one step, while -= subtracts and
assigns in one step.
Comparison operators check whether two values are equal, different, greater, or smaller.
The result is always true or false.
let age = 18;
console.log(age >= 18);
console.log(age === 18);
console.log(age != 20);
if
statements, loops, and form validation because they help JavaScript make decisions.
Logical operators work with conditions. They let you combine multiple checks or reverse a result.
let isLoggedIn = true;
let isAdmin = false;
console.log(isLoggedIn && isAdmin);
console.log(isLoggedIn || isAdmin);
console.log(!isAdmin);
These operators are useful when a decision depends on more than one condition.
The plus operator + can also join strings together. This is called string
concatenation.
let firstName = "Mim";
let lastName = "Akter";
let fullName = firstName + " " + lastName;
console.log(fullName);
+ adds. With strings, it joins text.
Operators are usually part of expressions. An expression combines values, variables, and operators to produce a result.
let result = (5 + 3) * 2;
In this line, the operators work together inside one expression, and JavaScript produces the final value.
true or false+ operator can add numbers or join strings