LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 7

A const shadowed in a block Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

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

main.js
const name = "global";
{
  const name = "block";
  console.log(name);
}
console.log(name);
  • A block global Correct
  • B block block
  • C global global
  • D SyntaxError
Correct Answer: Option A

The block has its own scope, so its const name shadows the outer one only inside the braces.

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