LearnFrenzy
Sign in Take a free test

Destructuring · Find the Error · Question 14

Bug: the setting does not change Answer, explanation & discussion

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

The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?

main.js
const settings = { volume: 50, muted: false };
let { volume } = settings;
volume += 10;                        // turn it up
console.log("Saved volume:", settings.volume);
  • A Destructuring copies the value into a new variable; changing volume does not change settings.volume – assign settings.volume += 10 Correct
  • B let variables cannot be changed
  • C volume must be declared with const
  • D += does not work with numbers from objects
Correct Answer: Option A

The variable and the property are independent after destructuring (for primitives). Update the object itself, or create a new one: { ...settings, volume: volume }.

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