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.
What Are Operators in Programming?
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.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.
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 Operators
total = 5 * 3 # Python → 15 (no “let”, no semicolon)
let or semicolons — you just write total = 5 * 3 and you’re done. One less thing to remember.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.
Increment and Decrement
++ adds 1. — subtracts 1. Used constantly inside loops to count up or down.
score++; // now 11
lives–; // now 2
score += 1 instead. There’s no shorthand for a single increment — score++ is a syntax error in Python.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 Comparison Operators Explained
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.
== already checks type too — 5 == "5" is False in Python. That’s exactly the “gotcha” JavaScript needs === to avoid.=== vs == in JavaScript — Why This Matters
In JavaScript specifically: == checks value only. === checks value AND type. This difference causes real bugs.
=== — never ==. In Python, just use == — it’s already strict about type.Logical Operators — Combining Conditions
Check multiple things in a single line.
AND Operator
Both must be trueBoth conditions must be true for the result to be true. If even one is false — the whole thing is false.
can_enter = age >= 18 and has_id # Python — spelled out
OR Operator
Just one must be trueOnly one condition needs to be true. If at least one passes — the result is true.
has_discount = is_student or is_senior # Python
NOT Operator
Flips the resultFlips the result. Turns true into false, and false into true.
if not is_logged_in: … # Python
&&, 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 Assignment
The = operator stores a value into a variable. It does not mean “equal to” — it means “store this value here.”
score = 20; // replace with 20
Shorthand Operators
Instead of writing score = score + 5, you can write score += 5. Same in both languages.
++, so count += 1 is how Python developers increment.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.
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:
5 << 1 // → 10 (shifting left doubles the number)
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.
status = “adult” if age >= 18 else “minor” # Python — order is different!
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.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 in Code
First
Second
Third
Fourth
>, ==) are evaluated next, then &&, then || last. So in 2 + 3 > 4 && true, the addition runs first, then the comparison, then the AND.Common Operator Mistakes (and How to Avoid Them)
The five bugs that trip up almost every beginner.
= assigns 18 to age instead of comparing — a classic bug that silently changes your data instead of throwing an obvious error./ 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.++/--. Always use += 1 / -= 1 instead.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
What are the 4 basic operators in programming?
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.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.Why does JavaScript have === but Python doesn’t?
=== 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.How many types of operators are there in programming?
in, not in).What is the ternary operator used for?
cond ? a : b. In Python: a if cond else b. Use it for short value picks — not for running multiple lines of logic.Does Python have ++ and –?
++ or -- at all — writing count++ in Python throws a syntax error. Use count += 1 or count -= 1 instead.What is short-circuit evaluation?
&& 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.