LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 13

A function that reads a later let Answer, explanation & discussion

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

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

main.js
function getValue() {
  return value;
}
let value = "set";
console.log(getValue());
  • A undefined
  • B ReferenceError: Cannot access 'value' before initialization
  • C null
  • D set Correct
Correct Answer: Option D

The TDZ is about time, not position: getValue is called after the let line has run, so value is initialised by then.

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