The non-values- undefined and null 14 Flashcards

1
Q

Define null and undefined

A

undefined: not initialized (variable) or not existing (property of an object)
null: intentional absence of a value aka placeholder for a future value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define truthy and falsy

A

Truthy is true if coerced to boolean, falsy is false if converted to boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the nullish ?? operator used for?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is logical assignment operator ??= used for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly