JavaScript Operators: The Fundamentals You Need to Know
Source: Dev.to
Introduction: The Silent Decision‑Makers in Your Code
Imagine you’re building a calculator. You enter two numbers.
Behind that simple action lies something powerful — operators.
Operators are the symbols that allow JavaScript to perform calculations, compare values, make decisions, and update data. If variables store data, operators are what make that data useful for operations.
let result = 5 + 3; // result is 8
5and3are operands (the values the operation works on).+is the operator (the action to perform).
Without operators, JavaScript would only store values — it wouldn’t do anything with them.
Categories of Operators
| Category | Operators | Purpose |
|---|---|---|
| Arithmetic | + - * / % ** | Perform mathematical calculations |
| Comparison | `== === != > = b); // true | |
| console.log(a = b); // true | ||
| console.log(a <= b); // false | ||
| console.log(a == b); // false | ||
| console.log(a != b); // true |
#### Loose vs. Strict Equality
```js
// Loose equality (==) – type conversion occurs
console.log(5 == "5"); // true
// Strict equality (===) – no type conversion
console.log(5 === "5"); // false
Logical Operators
Logical operators are the backbone of decision‑making in JavaScript. They combine or invert Boolean conditions.
| Operator | Description | Example |
|---|---|---|
&& | AND – true only if both operands are true | true && false // false |
|| | OR – true if at least one operand is true | true || false // true |
! | NOT – inverts a Boolean value | !true // false |
Truth Table
| A | B | A && B | A || B | !A |
|---|---|---|---|---|
| true | true | true | true | false |
| true | false | false | true | false |
| false | true | false | true | true |
| false | false | false | false | true |
Assignment Operators
Assignment operators update the value of a variable and often combine an arithmetic operation with assignment for brevity.
let score = 10;
score += 5; // equivalent to score = score + 5
console.log(score); // 15
score -= 3; // equivalent to score = score - 3
console.log(score); // 12
Conclusion
JavaScript operators may be small symbols, but they control how your program behaves. Mastering them means mastering the core mechanics of JavaScript logic:
- Perform calculations
- Compare values
- Drive decision‑making
- Update data efficiently
A solid grasp of operators is essential before moving on to functions, arrays, or asynchronous programming. Strong logic leads to predictable, maintainable applications.