Programming Operators Explained – Symbols, Types and How They Work

Every time your code does math, compares two values, or makes a decision — it uses operators. Operators are the symbols that tell your program what to do with data. Plus signs, equals signs, greater than symbols — you have seen them all before. In coding, they work the same way as in everyday math, just with a few extra tricks.

Arithmetic, comparison, logical & bitwise operators
Real code examples in JavaScript & Python
Common mistakes & how to avoid them
Operators at a glance
+Add
Subtract
==Equal
&&AND
%Modulo
?:Ternary
🚀 Step 6 of 13 · Beginner · ⏱️ 14 min read
⚙️ Operators

What Are Operators in Programming?

An operator is a symbol that tells the computer to perform a specific action on one or more values. The values it acts on are called operands — so in 7 + 3, the 7 and 3 are operands, and + is the operator. Put an operator and its operands together and you get an expression — a piece of code that produces a value. Every line of code you write is built from expressions like this.
🧮 Analogy

Real-Life Analogy — Calculator Buttons

Think of operators like buttons on a calculator. Your values (operands) sit on either side. The operator tells the computer what to do. The result gets stored in a variable.

⚡ calculator.js
let result = 7 + 3; // → 10
The operands go on either side. The operator tells the computer what to do. Together, they form an expression.
🧮

Arithmetic Operators — Doing Math

If you’ve used a calculator — you already know most of these.

These are the operators you use to do math in code. They work exactly like the math you learned in school — just written slightly differently. Every language has these, though a couple of small details change between JavaScript and Python (we’ll flag those as we go).

➕ Basic Math

Basic Math Operators

+
Addition
5 + 3 = 8
Subtraction
5 – 3 = 2
*
Multiply
5 * 3 = 15
/
Division
10 / 4 = 2.5
**
Power
2 ** 3 = 8
JavaScriptPython
⚡ math.js / math.py
let total = 5 * 3; // JS → 15
total = 5 * 3 # Python → 15 (no “let”, no semicolon)
💡 Python doesn’t use let or semicolons — you just write total = 5 * 3 and you’re done. One less thing to remember.
% Modulo

The Modulo Operator — Finding Remainders

% gives you the remainder after division. Perfect for checking if a number is even or odd — this is identical in JS and Python.

6 % 2
= 0
✅ Even number
7 % 2
= 1
❌ Odd number
10 % 3
= 1
1 left over
++ / — Shorthand

Increment and Decrement

++ adds 1. subtracts 1. Used constantly inside loops to count up or down.

➕ ++ Increment (JS only)
let score = 10;
score++; // now 11
Adds 1 to the variable
➖ — Decrement (JS only)
let lives = 3;
lives–; // now 2
Subtracts 1 from the variable
⚠️ Python doesn’t have ++ or –. This trips up almost every beginner switching languages. In Python you write score += 1 instead. There’s no shorthand for a single increment — score++ is a syntax error in Python.
⚖️ Comparison

Comparison Operators — Comparing Values

Comparison operators compare two values and always return true or false. Nothing else. This makes them perfect for making decisions in your if/else statements.

📊 All Operators

All Comparison Operators Explained

==
Equal to
5 == 5
true
!=
Not equal to
5 != 3
true
>
Greater than
5 > 3
true
<
Less than
5 < 3
false
>=
Greater or equal
5 >= 5
true
<=
Less or equal
3 <= 5
true
🐍 JS vs Python

Why JavaScript Has === and Python Doesn’t

This is the single most confusing thing for beginners moving between languages, so let’s be direct about it: Python only has == and !=. There is no === in Python — it isn’t valid syntax there at all. JavaScript has both == and === because JS quietly converts types for you unless you tell it not to. Python doesn’t do that silent conversion, so it never needed a “strict” version.

LanguageLoose/only equalityStrict equality
JS5 == “5” → true5 === “5” → false
Python5 == “5” → False(=== doesn’t exist)
💡 Fun fact: Python’s plain == already checks type too — 5 == "5" is False in Python. That’s exactly the “gotcha” JavaScript needs === to avoid.
⚠️ Important (JavaScript)

=== vs == in JavaScript — Why This Matters

In JavaScript specifically: == checks value only. === checks value AND type. This difference causes real bugs.

⚡ comparison.js
5 == “5” // true — ignores type!
❌ Avoid
5 === “5” // false — catches the difference
✅ Always Use
💡 Golden rule: In JavaScript, always use === — never ==. In Python, just use == — it’s already strict about type.
🔗 Logical Operators

Logical Operators — Combining Conditions

Check multiple things in a single line.

Logical operators let you combine two or more conditions together. Instead of checking one thing at a time — you can check multiple things in a single line.
&& / and

AND Operator

Both must be true

Both conditions must be true for the result to be true. If even one is false — the whole thing is false.

🌍 Real life: You can enter a club if you are over 18 AND have a valid ID. Both must pass.
JavaScriptPython
⚡ and.js / and.py
let canEnter = age >= 18 && hasID; // JS
can_enter = age >= 18 and has_id # Python — spelled out
true && truetrue
true && falsefalse
false && falsefalse
|| / or

OR Operator

Just one must be true

Only one condition needs to be true. If at least one passes — the result is true.

🌍 Real life: You get a discount if you are a student OR a senior citizen. Just one is enough.
JavaScriptPython
⚡ or.js / or.py
let hasDiscount = isStudent || isSenior; // JS
has_discount = is_student or is_senior # Python
true || falsetrue
false || falsefalse
true || truetrue
! / not

NOT Operator

Flips the result

Flips the result. Turns true into false, and false into true.

🌍 Real life: Show the login button only if the user is NOT already logged in.
JavaScriptPython
⚡ not.js / not.py
if (!isLoggedIn) { … } // JS
if not is_logged_in: … # Python
!truefalse
!falsetrue
Short-circuit evaluation: With &&, if the first condition is false, the second one is never even checked — the answer is already false. Same with ||: if the first is true, the second is skipped. This is why user && user.name is a safe way to check a nested value without crashing — if user is false, it never tries to read .name.
✏️

Assignment Operators — Shorthand Writing

Store values faster with less code.

Assignment operators store values into variables. You already know the basic one — =. These shorthand versions work identically in JavaScript and Python.

= Basic

Basic Assignment

The = operator stores a value into a variable. It does not mean “equal to” — it means “store this value here.”

⚡ assign.js
let score = 10; // store 10 in score
score = 20; // replace with 20
⚡ Shorthand

Shorthand Operators

Instead of writing score = score + 5, you can write score += 5. Same in both languages.

score += 5→ same as →score = score + 5
score -= 3→ same as →score = score – 3
score *= 2→ same as →score = score * 2
💡 You’ll use += the most — especially inside loops. Remember: Python has no ++, so count += 1 is how Python developers increment.
🔢 Bitwise

Bitwise Operators — Working with Bits

The advanced layer beneath every number.

Every number your computer stores is really a sequence of bits — 1s and 0s. Bitwise operators let you work directly with those bits instead of the “whole” number. You won’t need these every day as a beginner, but they show up in performance-critical code, permissions systems, and technical interviews — so it’s worth knowing they exist and roughly what they do.

&
AND
1 only if both bits are 1
|
OR
1 if either bit is 1
^
XOR
1 if bits are different
~
NOT
Flips every bit
<<
Left Shift
Shifts bits left (×2 per shift)
>>
Right Shift
Shifts bits right (÷2 per shift)

Seeing It in Bits: 5 & 3

5 in binary is 101, and 3 is 011. AND compares each column — both bits must be 1 for the result to be 1:

1
0
1
5
&
0
1
1
3
=
0
0
1
1
⚡ bitwise.js / bitwise.py
5 & 3 // → 1 (same syntax in JS and Python)
5 << 1 // → 10 (shifting left doubles the number)
💡 Same symbols, same behavior in both JavaScript and Python — one of the rare cases where nothing changes between languages.

The Ternary Operator — A One-Line If/Else

One question, two possible answers, zero curly braces.

The ternary (or conditional) operator is a shortcut for a simple if/else statement that only sets one value. It’s called “ternary” because it’s the only operator that takes three operands: a condition, a result if true, and a result if false.

age >= 18
condition
?
then
“adult”
if true
:
else
“minor”
if false
JavaScriptPython
⚡ ternary.js / ternary.py
let status = age >= 18 ? “adult” : “minor”; // JS
status = “adult” if age >= 18 else “minor” # Python — order is different!
⚠️ Watch the order: JavaScript reads condition-first (cond ? a : b), but Python reads value-first (a if cond else b). Mixing these up is one of the most common syntax errors when switching between the two languages.
Use a ternary when you’re just picking one of two values to store. If you need to run several lines of code depending on the condition, use a regular if/else instead — a ternary crammed with extra logic becomes hard to read.
⚡ Precedence

Operator Precedence — Which Runs First?

Code doesn’t always run left to right — it follows a specific order.

When you write an expression with multiple operators, the computer does not just run them left to right. It follows a specific order — just like BODMAS from math class. This order applies the same way in JavaScript and Python.

📋 Order of Operations

Order of Operations in Code

1
( )
Parentheses
First
2
**
Powers
Second
3
* /
Multiply/Divide
Third
4
+ –
Add/Subtract
Fourth
📍 After the math runs: comparisons (>, ==) are evaluated next, then &&, then || last. So in 2 + 3 > 4 && true, the addition runs first, then the comparison, then the AND.
10 + 5 * 2// → 20 not 30 — * runs before +
⚠️ Beginners expect 30 — but * runs first → 10 + 10 = 20
(10 + 5) * 2// → 30 — () forces + to run first
✅ Parentheses override everything — add first, then multiply
10 + 6 / 2 1// → 12 — / first, then + and –
💡 Division runs first → 10 + 3 – 1 = 12
💡 Golden rule: When in doubt — use parentheses. They make your intention clear to both the computer and anyone reading your code.
🚧 Common Mistakes

Common Operator Mistakes (and How to Avoid Them)

The five bugs that trip up almost every beginner.

1. Using = when you mean == (or ==)
if (age = 18) { … }
if (age == 18) { … }
A single = assigns 18 to age instead of comparing — a classic bug that silently changes your data instead of throwing an obvious error.
2. Expecting left-to-right math
10 + 5 * 2 // expecting 30
(10 + 5) * 2 // → 30, use parentheses
Multiplication and division always run before addition and subtraction — see the Precedence section above.
3. Forgetting integer division truncates (in some languages)
7 / 2 // JS → 3.5, but in some languages → 3
7 % 2 // use modulo when you need the remainder
JavaScript and Python’s / both return decimals. But if you’re used to languages like Java or C, / between two integers drops the decimal — always check what your language does.
4. Trying to use ++ or — in Python
count++ # SyntaxError in Python
count += 1 # correct in Python
Python simply doesn’t support ++/--. Always use += 1 / -= 1 instead.
5. Chaining comparisons the way you would in math class
if (0 < age < 18) { … } // JS: doesn’t do what you think
if (age > 0 && age < 18) { … } // combine with &&
In JavaScript, 0 < age < 18 evaluates left to right and almost always returns true by accident. (Python is actually one of the few languages where chained comparisons like this work as expected — another good reason to always know which language’s rules you’re in.)

FAQs About Operators

Quick answers to the questions beginners ask most

Q 01

What are the 4 basic operators in programming?

+
The 4 basic operators are Addition, Subtraction, Multiplication, and Division. They’re called arithmetic operators and are supported in every programming language — master these first.
Q 02

What does % mean in coding?

+
% is the modulo operator. It gives you the remainder after division — used to check even/odd numbers and to cycle through values in loops. Example: 10 % 3 = 1.
Q 03

What is the difference between = and == in coding?

+
= is assignment — it stores a value. == is comparison — it checks if two values are equal. Confusing them is one of the most common beginner bugs.
Q 04

Why does JavaScript have === but Python doesn’t?

+
JavaScript silently converts types during comparison unless you use === to stop it. Python never does this silent conversion, so its plain == already checks type — meaning === would be redundant, and it simply isn’t part of the language.
Q 05

How many types of operators are there in programming?

+
Most languages group operators into six categories: arithmetic (math), comparison (true/false checks), logical (combining conditions), assignment (storing values), bitwise (working with individual bits), and the ternary/conditional operator (a one-line if/else). Some languages add more, like Python’s membership operators (in, not in).
Q 06

What is the ternary operator used for?

+
The ternary operator is a one-line shortcut for a simple if/else that just picks one of two values. In JS: cond ? a : b. In Python: a if cond else b. Use it for short value picks — not for running multiple lines of logic.
Q 07

Does Python have ++ and –?

+
No. Python doesn’t support ++ or -- at all — writing count++ in Python throws a syntax error. Use count += 1 or count -= 1 instead.
Q 08

What is short-circuit evaluation?

+
It’s when && or || skip checking the second condition because the first one already determined the result. With &&, a false first condition means the whole expression is false — so the second half is never evaluated. This is why patterns like user && user.name are safe even if user doesn’t exist.
Q 09

What are bitwise operators used for in real projects?

+
Bitwise operators show up in permission systems (checking which flags are “on” using AND/OR), low-level performance optimizations, graphics/color code, and networking. As a beginner you won’t use them often, but they’re a common technical interview topic.
Still have questions? Browse our free tutorials.
Browse Tutorials →