LearnFrenzy
Sign in Take a free test

Conditional Statements · Find the Error · Question 10

Error: using a block variable before it is declared Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
const isMember = true;
if (isMember) {
  console.log("Discount:", discount);
  let discount = 10;
}
  • A ReferenceError: discount is used in its temporal dead zone, before let discount runs Correct
  • B It prints Discount: undefined
  • C It prints Discount: 10
  • D SyntaxError
Correct Answer: Option A

let is hoisted to the top of the block but not initialised until its line. Move the declaration above the console.log.

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