LearnFrenzy
Sign in Take a free test

ES6 Features · Find the Error · Question 11

Error: spreading an object into an array Answer, explanation & discussion

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

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
const scores = { maths: 90, science: 85 };
const list = [...scores];
console.log(list);
  • A TypeError: scores is not iterable – array spread needs an iterable; use Object.values(scores) Correct
  • B It prints [ 90, 85 ]
  • C It prints [ 'maths', 'science' ]
  • D It prints []
Correct Answer: Option A

Spread inside [ ] uses the iteration protocol, which plain objects do not implement. ({ ...scores } is fine – object spread copies properties.)

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