JavaScript
Nullish coalescing operator (??)
The Nullish coalescing operator ??
in JavaScript returns the right-hand value when the left-hand value is null
or undefined
, otherwise it returns the left-hand value.
const a = null ?? 'default' // 'default'
const b = undefined ?? 'default' // 'default'
const c = '' ?? 'default' // ''
const d = 0 ?? 'default' // 0
const e = false ?? 'default' // false