LearnFrenzy
Sign in Take a free test

Destructuring · Find the Error · Question 5

Error: a number as a destructuring target Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
const settings = { volume: 7 };
const { volume: 10 } = settings;
console.log(volume);
  • A It prints 7
  • B It prints 10
  • C SyntaxError: after the colon must come a variable name (or pattern) – a default is written with =: { volume = 10 } Correct
  • D ReferenceError
Correct Answer: Option C

In { prop: target }, the target must be a binding. To give a default, use = instead of :, or both: { volume: vol = 10 }.

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