LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 5

Is the outer name a variable? Answer, explanation & discussion

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

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

main.js
const { a: { b } } = { a: { b: 5 } };
console.log(b, typeof a);
  • A 5 object
  • B undefined object
  • C ReferenceError
  • D 5 undefined Correct
Correct Answer: Option D

Only the innermost name b is declared. a is just part of the path; typeof does not throw for an undeclared name.

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