Null and Undefined

Verze:

31. 12. 2025

Zodpovědná osoba:

Dominik Šlechta

Optional chaining MUST be used for potentially undefined properties. Nullish coalescing (??) MUST be used instead of || for default values.

Optional chaining MUST be used for potentially undefined properties.

Nullish coalescing (??) MUST be used instead of logical OR (||) for default values when 0 or empty string are valid values.

Example (Correct):

const city = user?.address?.city
const count = response.count ?? 0
const name = user.name ?? 'Anonymous'

Example (Incorrect):

// 0 would be replaced with 'default'
const value = response.count || 'default'