JavaScript Operators
A Guide to Programming Operators in JavaScript Language

Frontend Developer 💻 | Fueled by curiosity and Tea ☕ | Always learning and exploring new technologies.
In the world of programming, if variables are the nouns and functions are the sentences, then operators are the verbs.
They are the symbols that trigger action, transforming raw data into meaningful results.
Operators
Operators are for Mathematical and Logical Computations.
Whether you are working in JavaScript, C++, Python, or Java, the symbols and works of most operators remains remarkably consistent.
There are different types of JavaScript operators:
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Ternary Operators
Arithmetic Operators
If you are here, then I am sure you have done calculations like finding the sum of two numbers or converting a CTC to a monthly salary. In those moments, you were already using arithmetic operators.
So, Arithmetic operators are used to perform mathematical operations on numbers. They are generally used to perform addition, subtraction, multiplication, division, modulo, and exponential operations.
Operator | Name | Example | Result |
| Addition |
|
|
| Subtraction |
|
|
| Multiplication |
|
|
| Division |
|
|
| Modulus |
|
|
| Exponentiation |
|
|
Assignment Operators
Assignment operators are used to assign values to variables.
Basic Assignment (Equal to =)
The most common operator. It takes the value on the right and puts it into the variable on the left.
- Example:
x = 3;
Compound Assignment
As a developer, you will often want to change a value that is already there like adding some value to a score in a game. Instead of writing a long statements, we use shortcuts.
Commonly used Compound Assignment:
Operator | Name | Example | Equivalent to |
| Addition Assignment |
|
|
| Subtraction Assignment |
|
|
| Multiplication Assignment |
|
|
| Division Assignment |
|
|
| Modulus Assignment |
|
|
Advance Compound Assignments:
Operator | Name | What it does | Code Example | Equivalent to... |
| Logical AND Assignment | Only assign if the variable is already true (or has a value) |
|
|
| Logical OR Assignment | Only assign if the variable is falsy. |
| x || (x = 10) |
| Nullish Coalescing Assignment | Only assign if the variable is null or undefined. |
|
|
Comparison Operators
These compare two values and return a Boolean (true or false). They are the backbone of decision-making in code.
In JavaScript, we have two ways to check if things are equal.
Loose Equality (==):
It is like comparing a 5 (text) to a 5 (number).
JS says "same same!" and calls it true.
Strict Equality (===):
This is much stricter.
It asks, "Are the values the same and are the types the same?"
Under this rule, a "5" (text) is NOT the same as a 5 (number).
JS says "same same but different!"
Operator | Name | What it does | Example | Result |
| Equal to |
|
|
|
| Strict Equal |
|
|
|
| Not Equal |
|
|
|
| Strict Not Equal |
|
|
|
| Greater Than |
|
|
|
| Less Than |
|
|
|
| Greater or Equal |
|
|
|
| Less or Equal |
|
|
|
Logical Operators
Logical operators allow you to build complex logic by combining multiple "True/False" comparisons together.
AND (&&)
It only returns true if every single condition being checked is true. If even one part is false, the whole thing fails.
Example:
To enter a high-security building, you must have both your ID card AND your fingerprint scanned. If either is missing, you stay outside.
You can write it like, if (idCard && fingerPrintSuccess) { ... }
OR (||)
It returns true if at least one of the conditions is true. It only fails if everything is false.
Example:
To pay for a coffee, you can use either your UPI or pay cash. As long as you have one, you get your coffee.
You can write it like, if (cash || upi) { ... }
NOT (!)
The NOT operator is a "reverser." It takes a value and flips it to the opposite state.
Example:
I don't love you.
You can write it like, if (!love) { ... }
Logical Truth Table
This table shows how the computer processes these combinations.
AND (&&)
| A | B | A AND B |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
OR (||)
| A | B | A OR B |
|---|---|---|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |
NOT (!)
| A | !A |
|---|---|
| true | false |
| false | true |
Short-Circuit Evaluation
In an
&&operation, if the first part isfalse, the computer stops immediately because it knows the whole thing can never betrue.In an
||operation, if the first part istrue, it stops because it knows the whole thing is alreadytrue.
This is incredibly useful for preventing errors. For example: if (user && user.name) The computer checks if user exists first. If it doesn't, it stops before trying to read user.name, preventing your app from crashing!
Operand
The values used by an operator are known as operands.
Ternary Operator (? :)
The ternary operator is a short form of if...else. Since this operator requires three operands, it is known as a ternary operator.
syntax
condition ? valueIfTrue : valueIfFalse
Example
// With Ternarily operator
let age = 18;
let result = age >= 18 ? "Adult" : "Minor";
// Equivalent to
let result;
if (age >= 18) {
result = "Adult";
} else {
result = "Minor";
}
Nested Ternary statement
let score = 85;
let grade =
score >= 90 ? "A" :
score >= 75 ? "B" :
score >= 50 ? "C" :
"Fail";
As this operators require 3 operand so known as ternary operator.
Binary Operators
If an operator has two operands, it is known as a binary operator. Arithmetic, Comparison, Logical, and Assignment operators are examples of binary operators.
Unary Operators
If an operator has one operand, it is known as a unary operator.
Examples,
Logical Negation (
!): Flips a true value to false or vice versa (e.g.,!isTrue).Increment/Decrement (
++,--): Adds or subtracts one from a variable (e.g.,i++).Unary Plus/Minus (
+,-): Indicates a positive or negative number (e.g.,-5).
Precedence
Whether you were the topper of your class or a backbencher, you probably wondered at some point if the order of things really mattered. In life, maybe not always but in programming, order is everything.
Let’s start with a simple question.
What will this return?
console.log(10 + 5 * 2);
Take a second. Is it 30 or 20?
If you guessed 30, you’re thinking left to right:
(10 + 5) * 2 = 30
But JavaScript doesn’t think that way.
The actual answer is:
10 + (5 * 2) = 20
Why? Because multiplication has higher precedence than addition.
Why Operator Precedence Matters
Operator precedence decides the order in which operations are executed in an expression.
If you don’t understand it:
Your calculations may silently give wrong results.
Logical conditions may behave unexpectedly.
Now imagine this:
console.log(true || false && false);
What’s the result?
Many developers assume it evaluates left to right:
(true || false) && false
But that’s not how JavaScript evaluates it.
Logical AND (&&) has higher precedence than Logical OR (||).
So it actually becomes:
true || (false && false)
true || false
true
Subtle difference. Big impact.
The Rule of Thumb
JavaScript follows a predefined priority system called operator precedence.
And whenever you’re unsure use parentheses () to make your intention explicit.
console.log((10 + 5) * 2); // 30
Clear. Predictable. Safe.
Keep experimenting, keep breaking things, and most importantly, keep coding. The more you use these operators, the more natural they will feel in your daily development journey.
"In programming, the hard part isn't solving problems, but deciding what problems to solve."
— Paul Graham
Let's Connect! 🚀
I’m currently deep-diving into the JavaScript, building projects and exploring the internals of the web. If you're on a similar journey or just love talking about JavaScript, let’s stay in touch!
Connect on LinkedIn: Satpalsinh's Profile
Follow my Blog: blogs.satpal.cloud
Keep coding and keep building.






