JavaScript Operators
A Guide to Programming Operators in JavaScript Language

Frontend Developer 💻 | Fueled by curiosity and Tea ☕ | Always learning and exploring new technologies.
Search for a command to run...
A Guide to Programming Operators in JavaScript Language

Frontend Developer 💻 | Fueled by curiosity and Tea ☕ | Always learning and exploring new technologies.
No comments yet. Be the first to comment.
Master JavaScript from the ground up with a structured, easy-to-follow learning path designed for serious developers. This series starts with core fundamentals like variables, data types, and control flow, then gradually moves into deeper topics such as functions, scope, prototypes, asynchronous programming, and how the JavaScript engine works internally. Each lesson focuses on clarity and real understanding. You will learn not only how to write JavaScript, but why it behaves the way it does. Concepts are explained using simple examples, practical use cases, and clean coding patterns that reflect real-world development.
A guide to JavaScript's variable and data type system without losing your mind.
The Hidden Pipeline Behind Every AI Response

Lets understand Linux what I understand

Let's understand JSON Web token authentication in Node.js

Understand serving of files using express

We will understand how to upload files using Express and Multer

On this page
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 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
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 are used to assign values to variables.
=)The most common operator. It takes the value on the right and puts it into the variable on the left.
x = 3;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. |
|
|
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.
==):It is like comparing a 5 (text) to a 5 (number).
JS says "same same!" and calls it true.
===):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 allow you to build complex logic by combining multiple "True/False" comparisons together.
&&)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) { ... }
||)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) { ... }
!)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) { ... }
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 |
In an && operation, if the first part is false, the computer stops immediately because it knows the whole thing can never be true.
In an || operation, if the first part is true, it stops because it knows the whole thing is already true.
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!
The values used by an operator are known as operands.
? :)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.
If an operator has two operands, it is known as a binary operator. Arithmetic, Comparison, Logical, and Assignment operators are examples of binary 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).
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.
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.
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
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.