Skip to content
Sarj Code Standards

no-logical-or-fallback

Use nullish defaults or explicit falsy-value checks instead of logical OR fallbacks.

Why

Logical OR falls back for empty strings, zero and false as well as missing values. This hides which values should actually receive a default.

Fix

Use ?? for null or undefined. If an empty string, zero or false needs special handling, test that condition explicitly and preserve the intended behavior.

Examples

Before — flagged Do not hide empty-string fallback behavior
src/title.ts
export function title(value: string) {
return value.trim() || "Untitled";
}
After — preferred Preserve an intentional empty-string default
src/title.ts
export function title(value: string) {
const trimmed = value.trim();
return trimmed === "" ? "Untitled" : trimmed;
}

References