The non-values- undefined and null 14 Flashcards
Define null and undefined
undefined: not initialized (variable) or not existing (property of an object)
null: intentional absence of a value aka placeholder for a future value
Define truthy and falsy
Truthy is true if coerced to boolean, falsy is false if converted to boolean
what is the nullish ?? operator used for?
a ?? b
can be used in place of
a !== undefined && a !== null ? a : b
we use it for default values. sometimes we only want to use a value if it is not null or undefined. otherwise, we use a default fallback (b)
What is logical assignment operator ??= used for?
a ??= b
a ?? (a = b)
if a is null or undefined, assign b’s value to a. this works to set defaults for missing properties.