JavaScript275 Documents

Value Presence Checks

Use the shared isNothing and isSomething helpers to check whether a value is absent or present. Do not duplicate these checks with combinations of comparisons against undefined, null, or an empty string. Do not substitute truthiness checks when valid values such as 0 or false must be preserved. Keep the definition of absence in the shared helpers rather than reimplementing it in callers.

Philosophy

A shared definition of presence keeps checks concise and consistent. Callers should express whether a value is present without duplicating the rules that define absence.

Correct

const missing = isNothing(category)
const present = isSomething(category)
ensure(category, 'category').isSomething()

Incorrect

const missing = category === undefined || category === null || category === ''
const present = category !== undefined && category !== null && category !== ''

Fix

Replace manual absence checks with isNothing(value) and manual presence checks with isSomething(value), using the existing shared helpers.