Question 3
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
function test() {
console.log(v);
if (false) {
var v = 10;
}
console.log(v);
}
test();
- A undefined undefined Correct
- B ReferenceError
- C undefined 10
- D 10 10
Correct Answer: Option A
The declaration is hoisted during the creation phase even though the block never runs, so v exists as undefined. The assignment never happens.
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!