What is an Operator?
An operator is a symbol that tells JavaScript to perform a specific mathematical, relational, or logical operation and produce a result. An expression is any valid piece of code that resolves to a value — often built with operators.
For example: 5 + 3 is an expression that uses the addition operator +.
let total = price * quantity;, you're using operators to create a new value.
Arithmetic Operators
Use these to perform math operations on numbers.
+Addition-Subtraction*Multiplication/Division%Modulus (remainder)**Exponentiation (power)
Assignment Operators
Assign values to variables, often combined with arithmetic.
=Assigns a value+=Adds and assigns:x += 5is the same asx = x + 5-=Subtracts and assigns*=Multiplies and assigns/=Divides and assigns
Comparison Operators
Compare two values and return a boolean (true or false).
==Equal (loose equality, does type coercion)===Strict equal (recommended)!=Not equal (loose)!==Strict not equal (recommended)>Greater than<Less than>=Greater than or equal<=Less than or equal
=== and !==
Always prefer strict equality === over loose == to avoid unexpected type coercion bugs.
Logical Operators
Combine multiple conditions or invert boolean values.
&&AND — true only if both are true||OR — true if at least one is true!NOT — inverts the boolean value
Operator Precedence
Just like in math, operators have a precedence that determines the order in which they are evaluated. Multiplication and division happen before addition and subtraction.
let result = 5 + 3 * 2; // 11, not 16
Use parentheses () to make your intention clear and override precedence.
let result2 = (5 + 3) * 2; // 16
Common Mistakes
- Using
=(assignment) instead of===(comparison) in conditionals - Forgetting that
+also concatenates strings:"5" + 3 = "53" - Confusing
&&and||logic
Quick Quiz
1. What is the result of 10 % 3?
2. Which operator should you use for strict equality?
3. What does true && false return?
4. What is the value of x after let x = 5; x += 2;?
Summary
- Arithmetic operators:
+ - * / % ** - Assignment operators:
= += -= *= /= - Comparison operators:
=== !== > < >= <= - Logical operators:
&& || ! - Use
===and!==for strict comparisons - Use parentheses to control evaluation order
