Question 20
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
var a = "A";
function one() {
var a = "B";
function two() {
function three() {
return a;
}
return three();
}
return two();
}
console.log(one(), a);
- A A A
- B B B
- C B A Correct
- D undefined A
Correct Answer: Option C
three has no a, nor does two; the search reaches one(), which declares a = "B". The global a stays "A".
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!