LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 17

typeof a variable outside its block Answer, explanation & discussion

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

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

main.js
{
  let inner = 1;
}
console.log(typeof inner);
  • A undefined Correct
  • B number
  • C ReferenceError: inner is not defined
  • D object
Correct Answer: Option A

let is block-scoped, so inner does not exist outside the braces. typeof is the one operator that does not throw for an undeclared name – it returns "undefined".

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