jsverse
Fundamentals / Operators

Operators

Arithmetic, comparison, logical, and the newer safety operators.

Arithmetic operators (+, -, *, /, %, **) do math. Comparison operators (===, !==, <, >) test relationships — always prefer strict equality (===) over == to avoid type coercion surprises.

Two modern operators prevent whole classes of bugs: `??` (nullish coalescing) falls back only on null/undefined, unlike `||` which falls back on any falsy value. `?.` (optional chaining) short-circuits to undefined instead of throwing when a property along the chain doesn't exist.

Codeeditable — Run and Step both follow your edits
Loading...
Console
Output will appear here
Visualization
Result
Press Step to watch each line's result appear here
Why?

?? checks specifically for null or undefined, so a legitimate 0 or empty string survives. || checks for any falsy value, so it overwrites 0 even when 0 was the intended value.