LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Predict the Output · Question 15

A let in a block shadowing a parameter Answer, explanation & discussion

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

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

main.js
function f(x) {
  {
    let x = 2;
    x *= 10;
  }
  return x;
}
console.log(f(1));
  • A 20
  • B 2
  • C 1 Correct
  • D SyntaxError
Correct Answer: Option C

The inner let x lives in its own block and hides the parameter only there. (A let x directly in the function body, next to the parameter, would be a SyntaxError.)

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