LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 4

Rename with defaults, undefined and 0 Answer, explanation & discussion

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

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

main.js
const { x: renamed = 10, y: other = 20 } = { x: undefined, y: 0 };
console.log(renamed, other);
  • A 10 20
  • B undefined 0
  • C 10 0 Correct
  • D 0 20
Correct Answer: Option C

x is undefined, so its default 10 is used; y is 0, a defined value, so the default 20 is ignored.

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