What does undefined mean in JavaScript?
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
Give an example of how undefined can occur.
let myVar;
console.log(myVar); (Uninitialized variable)
Function with missing arguments
Accessing a non-existent object property.
N/A
What is the result of typeof undefined?
“undefined” (a string)
N/A
What does null mean in JavaScript?
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
Give an example of how null is used.
let myObject = null; (Explicitly setting a variable to represent “no object here”). Clearing a variable’s value.
N/A
What is the result of typeof null?
“object” (A historical quirk/bug! Be aware of this).
N/A
Explain the key difference between undefined and null.
undefined: Hasn’t been assigned a value yet.
null: Intentionally holds no value (is explicitly empty).
N/A
What does NaN mean in JavaScript?
“Not-a-Number”. Represents a value that is not a valid number. Result of an invalid numerical operation.
N/A
Give an example of how NaN can occur.
0 / 0
Math.sqrt(-1)
Parsing a non-numeric string (parseInt(“hello”))
N/A
What is the result of typeof NaN?
“number” (Even though it’s not a valid number).
N/A
How do you properly check if a value is NaN? Why can’t you use === NaN?
Use Number.isNaN(value). NaN === NaN is always false. Number.isNaN() does NOT type coerce.
N/A
What is the typeof operator?
A unary operator that returns a string indicating the data type of a value.
N/A
List the main return values of the typeof operator.
“undefined”, “object”, “boolean”, “number”, “string”, “symbol”, “function”
N/A
What is the typeof an array?
“object” (Arrays are objects in JavaScript).
N/A
Explain the benefit of using the strict equality operator (===) when comparing to null or undefined.
It avoids type coercion, which can lead to unexpected results.
N/A
When should you use optional chaining (?.) and nullish coalescing (??)
To handle situations where values might be null or undefined, providing safer property access (?.) and fallback defaults (??).
N/A