Question 4
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
function f() {
return typeof g;
var g = 5;
function g() {}
}
console.log(f());
- A number
- B undefined
- C function Correct
- D ReferenceError
Correct Answer: Option C
During creation, the function declaration g takes precedence over the var. The return runs before the assignment g = 5 could ever happen.
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!