JavaScript Special Values & typeof Flashcards

... (16 cards)

1
Q

What does undefined mean in JavaScript?

A

Absence of a defined value. A variable has been declared, but hasn’t been assigned a value. Or a property that doesn’t exist.

N/A

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

Give an example of how undefined can occur.

A

let myVar;
console.log(myVar); (Uninitialized variable)
Function with missing arguments
Accessing a non-existent object property.

N/A

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

What is the result of typeof undefined?

A

“undefined” (a string)

N/A

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

What does null mean in JavaScript?

A

The intentional absence of a value. It signifies that a variable currently holds no object (or is intentionally empty). It’s a deliberate assignment.

N/A

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

Give an example of how null is used.

A

let myObject = null; (Explicitly setting a variable to represent “no object here”). Clearing a variable’s value.

N/A

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

What is the result of typeof null?

A

“object” (A historical quirk/bug! Be aware of this).

N/A

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

Explain the key difference between undefined and null.

A

undefined: Hasn’t been assigned a value yet.
null: Intentionally holds no value (is explicitly empty).

N/A

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

What does NaN mean in JavaScript?

A

“Not-a-Number”. Represents a value that is not a valid number. Result of an invalid numerical operation.

N/A

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

Give an example of how NaN can occur.

A

0 / 0
Math.sqrt(-1)
Parsing a non-numeric string (parseInt(“hello”))

N/A

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

What is the result of typeof NaN?

A

“number” (Even though it’s not a valid number).

N/A

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

How do you properly check if a value is NaN? Why can’t you use === NaN?

A

Use Number.isNaN(value). NaN === NaN is always false. Number.isNaN() does NOT type coerce.

N/A

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

What is the typeof operator?

A

A unary operator that returns a string indicating the data type of a value.

N/A

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

List the main return values of the typeof operator.

A

“undefined”, “object”, “boolean”, “number”, “string”, “symbol”, “function”

N/A

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

What is the typeof an array?

A

“object” (Arrays are objects in JavaScript).

N/A

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

Explain the benefit of using the strict equality operator (===) when comparing to null or undefined.

A

It avoids type coercion, which can lead to unexpected results.

N/A

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

When should you use optional chaining (?.) and nullish coalescing (??)

A

To handle situations where values might be null or undefined, providing safer property access (?.) and fallback defaults (??).

N/A