Three typeof checks
Predict each line. For the last check, name the error type if there is one.
Code Snippet
const value = "outer";
function probe() {
console.log(typeof spare);
var spare = 7;
console.log(typeof notDeclaredHere);
try {
console.log(typeof value);
const value = 9;
} catch (error) {
console.log(error.name);
}
}
probe();Expected Output & Explanation
undefined
undefined
ReferenceError spare already exists with value undefined. typeof safely handles the missing name, but the inner value shadows the outer value and is still uninitialized. The first two printed values are strings.
Module Context & References
JavaScript · Language output drills Trace closures, receivers, prototypes, coercion and array edge cases
Personal Notes · Markdown