When dealing with possibly missing or nullable values (especially globals and config), make null/undefined handling explicit and never call a value unless you’ve verified its type.
Apply this standard:
x === undefined (or x !== undefined) rather than relying on implicit truthiness.maybeFn(...), ensure typeof maybeFn === 'function'.Example:
function isDocumentVisible(document) {
return (
document.visibilityState === undefined ||
document.visibilityState === 'visible' ||
document.visibilityState === 'prerender'
);
}
function shouldRetry(query, error) {
const retry = query.config.retry;
if (retry === true) return true;
if (typeof retry === 'number') return query.state.failureCount <= retry;
if (typeof retry === 'function') {
return retry(query.state.failureCount, error);
}
return false;
}
Enter the URL of a public GitHub repository