Lesson 4 of 55 · javascript
Operators & Expressions
Duration: 9 mins
Arithmetic, comparison, logical, bitwise, assignment, and ternary operators.
| Operator | Example | Meaning |
|---|---|---|
+ - * / % | 5 * 2 | arithmetic |
=== !== | a === b | strict equality |
&& || | a && b | logical AND / OR |
?: | cond ? a : b | ternary (inline if) |
?? | a ?? b | nullish coalescing |
?. | obj?.prop | optional chaining |
Example: Nullish coalescing vs logical OR
let foo = 0;
console.log(foo || 42); // 42 (because 0 is falsy)
console.log(foo ?? 42); // 0 (nullish coalescing only for null/undefined)