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= instead of === in a condition. if (age = 18) assigns 18 to age and the condition is always truthy — it doesn't compare anything. This is one of the most common JavaScript bugs.
+ always adds numbers. If either side is a string — often from a form input, which is always text — + concatenates instead: "5" + 5 gives "55", not 10.
== instead of ===. Loose equality coerces types before comparing, so "0" == 0 is true. Strict equality avoids that entirely.
This is the exact bug that happens when reading a number from an HTML input and forgetting to convert it:
let priceFromInput = "50"; // form inputs are always strings
let quantity = 3;
let wrongTotal = priceFromInput + quantity; // "503" (concatenated!)
let rightTotal = Number(priceFromInput) * quantity; // 150 (correct)
console.log(wrongTotal, rightTotal);
Q: What's the difference between == and ===?
A: == converts types before comparing (loose equality); === compares both value and type with no conversion (strict equality). Use === by default.
Q: Why did "5" + 5 give "55" instead of 10?
A: Because one side is a string, JavaScript's + operator switches to string concatenation instead of arithmetic. Wrap the string in Number() first if you need math.
Q: What does the % operator do?
A: It's the remainder (modulo) operator — 7 % 2 is 1. Commonly used to check even/odd numbers. See the MDN operators reference for the full list.