LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 10

typeof before and after an assignment Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
function test() {
  console.log(typeof x);
  var x = 10;
  function x() {}
  console.log(typeof x);
}
test();
  • A function number Correct
  • B undefined number
  • C number function
  • D function function
Correct Answer: Option A

Creation phase: x is the function. Execution phase: var x = 10 assigns a number; the function declaration line itself does nothing at run time.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links