LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 5

A var assignment after a function declaration Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

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

main.js
var greet = "hello";
function greet() {
  return "fn";
}
console.log(typeof greet);
  • A function
  • B undefined
  • C string Correct
  • D object
Correct Answer: Option C

The function is created first (hoisting), then line 1 runs and assigns the string, replacing it.

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