JavaScript operators perform math, assign values, compare data, and combine boolean conditions. Knowing how operators interact and which ones run first helps you write bug-free expressions across real applications.
JavaScript groups operators by the kind of work they perform on values (called operands):
| Category | Common Operators | Purpose |
|---|---|---|
| Arithmetic | +, -, *, /, %, ** |
Perform math and remainders |
| Comparison | ===, !==, >, <, >=, <= |
Return true or false |
| Logical | &&, ` |
|
| Ternary | condition ? a : b |
Inline conditional expression |
Logical operators short-circuit from left to right. When the left side of && is falsy, JavaScript skips evaluating the right side completely. The same shortcut applies when the left side of || is truthy.
?? vs ||Use the nullish coalescing operator (??) when you want a fallback only for null or undefined. Unlike ||, ?? keeps valid falsy values such as 0, "", or false.
const userPort = 0;
const safePort = userPort ?? 8080; // Keeps 0
const wrongPort = userPort || 8080; // Falls back to 8080!
const isLoggedIn = true;
const isAdmin = false;
const badge = isLoggedIn && isAdmin ? "Admin Panel" : "Member View";
console.log({ safePort, wrongPort, badge });
JavaScript evaluates * and / before + and -, and evaluates && before ||. Whenever an expression mixes multiple operators, wrap parts in parentheses (...) so intent stays crystal clear to every reader.
== instead of ===: Loose equality converts types behind the scenes ("5" == 5 is true), causing subtle bugs. Always use strict === and !==.|| and ??: Using count || 10 replaces 0 with 10. Use count ?? 10 for numeric defaults.? : operators on one line is hard to read; switch to if...else blocks instead.&& and || in JavaScript?&& returns the first falsy operand or the last operand if all are truthy. || returns the first truthy operand or the last operand if all are falsy.
typeof operator return?typeof is a unary operator that returns a lowercase string naming the operand's type, such as "number", "string", or "boolean".
The ternary operator cond ? valA : valB evaluates cond and returns valA when truthy or valB when falsy.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.