JavaScript operators do more than basic math and comparisons. Some powerful yet often overlooked operators can simplify your code and solve tricky problems elegantly. Here are five essential operators you should master.
1. Nullish Coalescing (??) – Smarter Defaults
The ?? operator checks if a value is null or undefined (not just falsy like ||).
Why it matters?
- Avoids unexpected fallbacks with
0,"", orfalse - Perfect for API responses where
0or""are valid
2. Optional Chaining (?.) – Safe Nested Access
The ?. operator prevents errors when accessing deeply nested properties.
Why it matters?
- Eliminates verbose
&&checks - Works with functions and arrays too
3. Logical Assignment (&&=, ||=, ??=) – Compact Updates
These operators assign values only if a condition is met.
Why it matters?
- Replaces repetitive
ifchecks - Cleaner state management
4. Spread (...) – Clone & Merge Objects/Arrays
The ... operator expands iterables into individual elements.
Why it matters?
- Immutable updates without mutating originals
- Merging objects/arrays effortlessly
5. Destructuring – Unpack with Precision
While not a single operator, destructuring ({ }/[ ]) is indispensable.
Why it matters?
- Extracts multiple properties in one line
- Rename variables, set defaults
Which operator do you use most? Let me know in the comments!