JavaScript Operators Cheatsheet
š§® JavaScript Operators Cheatsheet
Operators perform actions on values and variables. This cheatsheet covers arithmetic, comparison, logical, assignment, and modern operators you use every day.
ā Arithmetic operators ā Comparison operators ā Logical operators ā Assignment operators ā Unary operators ā Ternary operator ā Optional chaining ā Nullish coalescing
#javascript #operators #arithmetic #comparison #logical #syntax #webdev #frontend #coding #tips
Arithmetic operators
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 3 | 2 |
* | Multiplication | 5 * 3 | 15 |
/ | Division | 6 / 3 | 2 |
% | Remainder | 7 % 3 | 1 |
** | Exponentiation | 2 ** 3 | 8 |
Comparison operators
| Operator | Name | Example | Result |
|---|---|---|---|
== | Loose equality | 5 == "5" | true |
=== | Strict equality | 5 === "5" | false |
!= | Loose inequality | 5 != "5" | false |
!== | Strict inequality | 5 !== "5" | true |
> | Greater than | 5 > 3 | true |
< | Less than | 5 < 3 | false |
>= | Greater or equal | 5 >= 5 | true |
<= | Less or equal | 5 <= 4 | false |
Logical operators
| Operator | Name | Description |
|---|---|---|
|| | OR | Returns first truthy value or last value |
&& | AND | Returns first falsy value or last value |
! | NOT | Converts to boolean and inverts |
?? | Nullish coalescing | Returns right side only if left is null or undefined |
Assignment operators
| Operator | Example | Equivalent |
|---|---|---|
= | x = 5 | x = 5 |
+= | x += 5 | x = x + 5 |
-= | x -= 5 | x = x - 5 |
*= | x *= 5 | x = x * 5 |
/= | x /= 5 | x = x / 5 |
%= | x %= 5 | x = x % 5 |
**= | x **= 2 | x = x ** 2 |
Unary operators
| Operator | Name | Example | Result |
|---|---|---|---|
++ | Increment | let x = 5; x++ | 6 |
-- | Decrement | let x = 5; x-- | 4 |
+ | Unary plus | +"42" | 42 |
- | Unary negation | -(5) | -5 |
typeof | Type check | typeof 5 | "number" |
delete | Delete property | delete obj.x | removes x |
Ternary operator
A compact alternative for if...else expression.
const age = 20;
const status = age >= 18 ? "adult" : "minor";
console.log(status); // "adult"Optional chaining (?.)
Safely access nested properties without throwing if a reference is null or undefined.
const user = { profile: { name: "Ada" } };
console.log(user.profile?.name); // "Ada"
console.log(user.settings?.theme); // undefinedNullish coalescing (??)
Returns the right-hand value, only when the left-hand side is null or undefined.
const value = 0;
console.log(value ?? 10); // 0
const missing = null;
console.log(missing ?? "fallback"); // "fallback"Full-Stack AI Developer Roadmap
From HTML & CSS to working with AI models, all in one structured roadmap.