Question 8
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
function outer() {
function inner() {
var secret = 42;
}
inner();
return typeof secret;
}
console.log(outer());
- A number
- B undefined Correct
- C 42
- D ReferenceError
Correct Answer: Option B
secret belongs to inner()'s function scope. outer cannot see it, and typeof returns "undefined" for an unresolvable name instead of throwing.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!